MCPcopy Create free account
hub / github.com/damms005/devdb-vscode / makeRequestWithRetry

Function makeRequestWithRetry

src/services/http-client.ts:39–68  ·  view source on GitHub ↗
(
  url: string,
  options: RequestConfig = {},
  currentAttempt = 1
)

Source from the content-addressed store, hash-verified

37}
38
39async function makeRequestWithRetry<T = any>(
40 url: string,
41 options: RequestConfig = {},
42 currentAttempt = 1
43): Promise<HttpResponse<T>> {
44 const retryConfig = {
45 ...DEFAULT_RETRY_CONFIG,
46 ...options.retry
47 };
48
49 try {
50 return await makeRequest<T>(url, options);
51 } catch (error) {
52 const shouldRetry = error instanceof Object &&
53 'status' in error &&
54 retryConfig.retryStatusCodes?.includes(error.status as number) &&
55 currentAttempt < retryConfig.maxRetries;
56
57 if (!shouldRetry) {
58 throw error;
59 }
60
61 const delayMs = retryConfig.exponentialBackoff
62 ? retryConfig.delayMs * Math.pow(2, currentAttempt - 1)
63 : retryConfig.delayMs;
64
65 await sleep(delayMs);
66 return makeRequestWithRetry<T>(url, options, currentAttempt + 1);
67 }
68}
69
70function makeRequest<T = any>(url: string, options: RequestConfig = {}): Promise<HttpResponse<T>> {
71 return new Promise((resolve, reject) => {

Callers 4

getMethod · 0.85
postMethod · 0.85
putMethod · 0.85
deleteMethod · 0.85

Calls 1

sleepFunction · 0.85

Tested by

no test coverage detected