@@ -10,7 +10,15 @@ async function sleep(ms: number): Promise<void> {
10
10
return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) )
11
11
}
12
12
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 > (
14
22
operation : ( ) => Promise < T > ,
15
23
maxRetries : number = 5 ,
16
24
baseDelay : number = 1000
@@ -23,6 +31,11 @@ async function retryWithExponentialBackoff<T>(
23
31
} catch ( error ) {
24
32
lastError = error as Error
25
33
34
+ // If the error is non-retriable, throw it immediately
35
+ if ( lastError instanceof NonRetriableError ) {
36
+ throw lastError
37
+ }
38
+
26
39
if ( attempt === maxRetries ) {
27
40
throw lastError
28
41
}
@@ -68,11 +81,13 @@ export async function submitFeedback(
68
81
}
69
82
}
70
83
)
71
- if ( ! response . ok ) {
72
- throw new Error ( `Failed to submit feedback: ${ response . statusText } ` )
73
- }
74
84
const resp = ( await response . json ( ) ) as GradeResponse
75
85
if ( resp . error ) {
86
+ if ( ! resp . error . recoverable ) {
87
+ throw new NonRetriableError (
88
+ `Failed to submit feedback: ${ resp . error . details } `
89
+ )
90
+ }
76
91
throw new Error (
77
92
`Failed to submit feedback: ${ resp . error . message } ${ resp . error . details } `
78
93
)
@@ -95,11 +110,13 @@ export async function createSubmission(token: string) {
95
110
}
96
111
}
97
112
)
98
- if ( ! response . ok ) {
99
- throw new Error ( `Failed to create submission: ${ response . statusText } ` )
100
- }
101
113
const resp = ( await response . json ( ) ) as SubmissionResponse
102
114
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
+ }
103
120
throw new Error (
104
121
`Failed to create submission: ${ resp . error . message } ${ resp . error . details } `
105
122
)
@@ -125,13 +142,13 @@ export async function createRegressionTestRun(
125
142
}
126
143
}
127
144
)
128
- if ( ! response . ok ) {
129
- throw new Error (
130
- `Failed to create regression test run: ${ response . statusText } `
131
- )
132
- }
133
145
const resp = ( await response . json ( ) ) as RegressionTestRunResponse
134
146
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
+ }
135
152
throw new Error (
136
153
`Failed to create regression test run: ${ resp . error . message } ${ resp . error . details } `
137
154
)
0 commit comments