MCPcopy Index your code
hub / github.com/simstudioai/sim / fetchWithRetry

Function fetchWithRetry

apps/sim/lib/knowledge/documents/utils.ts:182–215  ·  view source on GitHub ↗
(
  url: string,
  options: RequestInit = {},
  retryOptions: RetryOptions = {}
)

Source from the content-addressed store, hash-verified

180 * Wrapper for fetch requests with retry logic
181 */
182export async function fetchWithRetry(
183 url: string,
184 options: RequestInit = {},
185 retryOptions: RetryOptions = {}
186): Promise<Response> {
187 return retryWithExponentialBackoff(async () => {
188 const response = await fetch(url, options)
189
190 // If response is not ok and status indicates rate limiting, throw an error
191 if (!response.ok && isRetryableError({ status: response.status })) {
192 const errorText = await response.text()
193 const error: HTTPError = new Error(
194 `HTTP ${response.status}: ${response.statusText} - ${errorText}`
195 )
196 error.status = response.status
197 error.statusText = response.statusText
198
199 // Pass Retry-After to the retry loop so it replaces exponential backoff
200 const retryAfter = response.headers.get('Retry-After')
201 if (retryAfter) {
202 const waitMs = Number.isNaN(Number(retryAfter))
203 ? Math.max(0, new Date(retryAfter).getTime() - Date.now())
204 : Number(retryAfter) * 1000
205 if (waitMs > 0) {
206 error.retryAfterMs = waitMs
207 }
208 }
209
210 throw error
211 }
212
213 return response
214 }, retryOptions)
215}

Callers 15

getConfluenceCloudIdFunction · 0.90
downloadJiraAttachmentsFunction · 0.90
getJiraCloudIdFunction · 0.90
fetchNewOutlookEmailsFunction · 0.90
resolveWellKnownFolderIdFunction · 0.90
markOutlookEmailAsReadFunction · 0.90
webflow.tsFile · 0.90
fetchCollectionIdsFunction · 0.90
fetchFormStructureFunction · 0.90
fetchFormResponsesFunction · 0.90

Calls 4

isRetryableErrorFunction · 0.85
textMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected