MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / retryRequest

Method retryRequest

packages/cloud/src/retry-queue/RetryQueue.ts:195–246  ·  view source on GitHub ↗
(request: QueuedRequest)

Source from the content-addressed store, hash-verified

193 }
194
195 private async retryRequest(request: QueuedRequest): Promise<Response> {
196 this.log(`[RetryQueue] Retrying request: ${request.url}`)
197
198 let headers = { ...request.options.headers }
199 if (this.authHeaderProvider) {
200 const freshAuthHeaders = this.authHeaderProvider()
201 if (freshAuthHeaders) {
202 headers = {
203 ...headers,
204 ...freshAuthHeaders,
205 }
206 }
207 }
208
209 const controller = new AbortController()
210 const timeoutId = setTimeout(() => controller.abort(), this.config.requestTimeout)
211
212 try {
213 const response = await fetch(request.url, {
214 ...request.options,
215 signal: controller.signal,
216 headers: {
217 ...headers,
218 "X-Retry-Queue": "true",
219 },
220 })
221
222 clearTimeout(timeoutId)
223
224 // Check for error status codes that should trigger retry
225 if (!response.ok) {
226 // Handle different status codes appropriately
227 if (response.status >= 500) {
228 // Server errors (5xx) should be retried
229 throw new Error(`Server error: ${response.status} ${response.statusText}`)
230 } else if (response.status === 429) {
231 // Rate limiting - return response to let caller handle Retry-After
232 return response
233 } else if (response.status >= 400 && response.status < 500) {
234 // Client errors (4xx including 401/403) should NOT be retried
235 // These errors indicate problems with the request itself that won't be fixed by retrying
236 this.log(`[RetryQueue] Non-retryable client error ${response.status}, removing from queue`)
237 return response
238 }
239 }
240
241 return response
242 } catch (error) {
243 clearTimeout(timeoutId)
244 throw error
245 }
246 }
247
248 private startRetryTimer(): void {
249 if (this.retryTimer) {

Callers 1

retryAllMethod · 0.95

Calls 2

logMethod · 0.65
abortMethod · 0.45

Tested by

no test coverage detected