Skip to content

Commit ef1c639

Browse files
committed
Avoid retrying on non-retriable errors
1 parent da36ee2 commit ef1c639

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

dist/SupabaseAPI.d.ts

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js

Lines changed: 20 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/SupabaseAPI.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@ async function sleep(ms: number): Promise<void> {
1010
return new Promise((resolve) => setTimeout(resolve, ms))
1111
}
1212

13-
async function retryWithExponentialBackoff<T>(
13+
export class NonRetriableError extends Error {
14+
constructor(message: string, cause?: Error) {
15+
super(message)
16+
this.name = 'Error'
17+
this.cause = cause
18+
}
19+
}
20+
21+
export async function retryWithExponentialBackoff<T>(
1422
operation: () => Promise<T>,
1523
maxRetries: number = 5,
1624
baseDelay: number = 1000
@@ -23,6 +31,11 @@ async function retryWithExponentialBackoff<T>(
2331
} catch (error) {
2432
lastError = error as Error
2533

34+
// If the error is non-retriable, throw it immediately
35+
if (lastError instanceof NonRetriableError) {
36+
throw lastError
37+
}
38+
2639
if (attempt === maxRetries) {
2740
throw lastError
2841
}
@@ -68,11 +81,13 @@ export async function submitFeedback(
6881
}
6982
}
7083
)
71-
if (!response.ok) {
72-
throw new Error(`Failed to submit feedback: ${response.statusText}`)
73-
}
7484
const resp = (await response.json()) as GradeResponse
7585
if (resp.error) {
86+
if (!resp.error.recoverable) {
87+
throw new NonRetriableError(
88+
`Failed to submit feedback: ${resp.error.details}`
89+
)
90+
}
7691
throw new Error(
7792
`Failed to submit feedback: ${resp.error.message} ${resp.error.details}`
7893
)
@@ -95,11 +110,13 @@ export async function createSubmission(token: string) {
95110
}
96111
}
97112
)
98-
if (!response.ok) {
99-
throw new Error(`Failed to create submission: ${response.statusText}`)
100-
}
101113
const resp = (await response.json()) as SubmissionResponse
102114
if (resp.error) {
115+
if (!resp.error.recoverable) {
116+
throw new NonRetriableError(
117+
`Failed to create submission: ${resp.error.message} ${resp.error.details}`
118+
)
119+
}
103120
throw new Error(
104121
`Failed to create submission: ${resp.error.message} ${resp.error.details}`
105122
)
@@ -125,13 +142,13 @@ export async function createRegressionTestRun(
125142
}
126143
}
127144
)
128-
if (!response.ok) {
129-
throw new Error(
130-
`Failed to create regression test run: ${response.statusText}`
131-
)
132-
}
133145
const resp = (await response.json()) as RegressionTestRunResponse
134146
if (resp.error) {
147+
if (!resp.error.recoverable) {
148+
throw new NonRetriableError(
149+
`Failed to create regression test run: ${resp.error.message} ${resp.error.details}`
150+
)
151+
}
135152
throw new Error(
136153
`Failed to create regression test run: ${resp.error.message} ${resp.error.details}`
137154
)

0 commit comments

Comments
 (0)