Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: allow skipping retries on specific pathnames (#39894)

Alaister Young47fdedefbccc
diff --git a/apps/studio/data/fetchers.ts b/apps/studio/data/fetchers.ts
index f0ca332c3b5..6b2969b8217 100644
--- a/apps/studio/data/fetchers.ts
+++ b/apps/studio/data/fetchers.ts
@@ -105,10 +105,15 @@ client.use(
// add code field to body
body.code = response.status
+
body.requestId = request.headers.get('X-Request-Id')
+
const retryAfterHeader = response.headers.get('Retry-After')
body.retryAfter = retryAfterHeader ? parseInt(retryAfterHeader) : undefined
+ const requestUrl = new URL(request.url)
+ body.requestPathname = requestUrl.pathname
+
return new Response(JSON.stringify(body), {
headers: response.headers,
status: response.status,
@@ -156,9 +161,13 @@ export const handleError = (error: unknown, options: HandleErrorOptions = {}): n
'requestId' in error && typeof error.requestId === 'string' ? error.requestId : undefined
const retryAfter =
'retryAfter' in error && typeof error.retryAfter === 'number' ? error.retryAfter : undefined
+ const requestPathname =
+ 'requestPathname' in error && typeof error.requestPathname === 'string'
+ ? error.requestPathname
+ : undefined
if (errorMessage) {
- throw new ResponseError(errorMessage, errorCode, requestId, retryAfter)
+ throw new ResponseError(errorMessage, errorCode, requestId, retryAfter, requestPathname)
}
}
diff --git a/apps/studio/data/query-client.ts b/apps/studio/data/query-client.ts
index e2535c3bf5e..bec055c21ee 100644
--- a/apps/studio/data/query-client.ts
+++ b/apps/studio/data/query-client.ts
@@ -1,6 +1,8 @@
import { QueryClient, onlineManager } from '@tanstack/react-query'
-import { IS_PLATFORM } from 'lib/constants'
+import { match } from 'path-to-regexp'
import { useState } from 'react'
+
+import { IS_PLATFORM } from 'lib/constants'
import { ResponseError } from 'types'
// When running locally we don't need the internet
@@ -9,6 +11,13 @@ if (!IS_PLATFORM) {
onlineManager.setOnline(true)
}
+const SKIP_RETRY_PATHNAME_MATCHERS = [
+ '/platform/projects/:ref/run-lints',
+ '/platform/organizations/:slug/usage',
+ '/platform/pg-meta/:ref/query',
+ '/v1/projects/:ref/analytics/endpoints/logs.all',
+].map((pathname) => match(pathname))
+
let queryClient: QueryClient | undefined
export function getQueryClient() {
@@ -31,6 +40,14 @@ export function getQueryClient() {
return false
}
+ if (
+ error instanceof ResponseError &&
+ error.requestPathname &&
+ SKIP_RETRY_PATHNAME_MATCHERS.some((matchFn) => matchFn(error.requestPathname!))
+ ) {
+ return false
+ }
+
if (failureCount < 3) {
return true
}
diff --git a/apps/studio/types/base.ts b/apps/studio/types/base.ts
index 04847b64c66..1c477202c4c 100644
--- a/apps/studio/types/base.ts
+++ b/apps/studio/types/base.ts
@@ -89,12 +89,20 @@ export class ResponseError extends Error {
code?: number
requestId?: string
retryAfter?: number
+ requestPathname?: string
- constructor(message: string | undefined, code?: number, requestId?: string, retryAfter?: number) {
+ constructor(
+ message: string | undefined,
+ code?: number,
+ requestId?: string,
+ retryAfter?: number,
+ requestPathname?: string
+ ) {
super(message || 'API error happened while trying to communicate with the server.')
this.code = code
this.requestId = requestId
this.retryAfter = retryAfter
+ this.requestPathname = requestPathname
}
}