Skip to content

Commit 6eca983

Browse files
committed
feat(postgrest): restore x-retry-count header
1 parent 68e98cf commit 6eca983

6 files changed

Lines changed: 630 additions & 539 deletions

File tree

‎packages/core/postgrest-js/src/PostgrestBuilder.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ export default abstract class PostgrestBuilder<
223223

224224
while (true) {
225225
const requestHeaders = new Headers(this.headers)
226+
if (attemptCount > 0) {
227+
requestHeaders.set('X-Retry-Count', String(attemptCount))
228+
}
226229

227230
try {
228231
const res = await _fetch(this.url.toString(), {

‎packages/core/postgrest-js/src/PostgrestQueryBuilder.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,34 @@ export default class PostgrestQueryBuilder<
2222
fetch?: Fetch
2323
urlLengthLimit: number
2424

25-
// Retry configuration
25+
/**
26+
* Enable or disable automatic retries for transient errors.
27+
* When enabled, idempotent requests (GET/HEAD/OPTIONS) that fail with 520 or 503 errors
28+
* are automatically retried with exponential backoff (up to 3 attempts).
29+
* Defaults to `true` when not specified.
30+
*/
2631
retry?: boolean
2732

2833
/**
2934
* Creates a query builder scoped to a Postgres table or view.
3035
*
3136
* @category Database
3237
*
38+
* @param url - The URL for the query
39+
* @param options - Named parameters
40+
* @param options.headers - Custom headers
41+
* @param options.schema - Postgres schema to use
42+
* @param options.fetch - Custom fetch implementation
43+
* @param options.urlLengthLimit - Maximum URL length before warning
44+
* @param options.retry - Enable automatic retries for transient errors (default: true)
45+
*
3346
* @example Creating a Postgrest query builder
3447
* ```ts
3548
* import { PostgrestQueryBuilder } from '@supabase/postgrest-js'
3649
*
3750
* const query = new PostgrestQueryBuilder(
3851
* new URL('https://xyzcompany.supabase.co/rest/v1/users'),
39-
* { headers: { apikey: 'public-anon-key' } }
52+
* { headers: { apikey: 'public-anon-key' }, retry: true }
4053
* )
4154
* ```
4255
*/

0 commit comments

Comments
 (0)