MCPcopy
hub / github.com/triggerdotdev/trigger.dev / shouldRetry

Function shouldRetry

packages/core/src/v3/apiClient/core.ts:250–287  ·  view source on GitHub ↗
(
  response: Response,
  attempt: number,
  retryOptions?: RetryOptions
)

Source from the content-addressed store, hash-verified

248 };
249
250function shouldRetry(
251 response: Response,
252 attempt: number,
253 retryOptions?: RetryOptions
254): ShouldRetryResult {
255 function shouldRetryForOptions(): ShouldRetryResult {
256 const retry = { ...defaultRetryOptions, ...retryOptions };
257
258 const delay = calculateNextRetryDelay(retry, attempt);
259
260 if (delay) {
261 return { retry: true, delay };
262 } else {
263 return { retry: false };
264 }
265 }
266
267 // Note this is not a standard header.
268 const shouldRetryHeader = response.headers.get("x-should-retry");
269
270 // If the server explicitly says whether or not to retry, obey.
271 if (shouldRetryHeader === "true") return shouldRetryForOptions();
272 if (shouldRetryHeader === "false") return { retry: false };
273
274 // Retry on request timeouts.
275 if (response.status === 408) return shouldRetryForOptions();
276
277 // Retry on lock timeouts.
278 if (response.status === 409) return shouldRetryForOptions();
279
280 // Retry on rate limits.
281 if (response.status === 429) return shouldRetryForOptions();
282
283 // Retry internal errors.
284 if (response.status >= 500) return shouldRetryForOptions();
285
286 return { retry: false };
287}
288
289function safeJsonParse(text: string): any {
290 try {

Callers 1

_doZodFetchFunction · 0.70

Calls 2

shouldRetryForOptionsFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…