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

Function doFetchRequest

packages/trigger-sdk/src/v3/retry.ts:364–410  ·  view source on GitHub ↗
(
  input: RequestInfo | URL | string,
  init?: RequestInit,
  attemptCount: number = 0
)

Source from the content-addressed store, hash-verified

362}
363
364const doFetchRequest = async (
365 input: RequestInfo | URL | string,
366 init?: RequestInit,
367 attemptCount: number = 0
368): Promise<[Response, Span]> => {
369 const httpMethod = normalizeHttpMethod(input, init);
370
371 const span = tracer.startSpan(`HTTP ${httpMethod}`, {
372 attributes: {
373 [SemanticInternalAttributes.STYLE_ICON]: "world",
374 ...(attemptCount > 1 ? { ["http.request.resend_count"]: attemptCount - 1 } : {}),
375 ...createFetchAttributes(input, init),
376 },
377 });
378
379 try {
380 const response = await fetchWithInterceptors(input, {
381 ...init,
382 headers: {
383 ...init?.headers,
384 "x-retry-count": attemptCount.toString(),
385 },
386 });
387
388 span.setAttributes(createFetchResponseAttributes(response));
389
390 if (!response.ok) {
391 span.recordException(`${response.status}: ${response.statusText}`);
392 span.setStatus({
393 code: SpanStatusCode.ERROR,
394 message: `${response.status}: ${response.statusText}`,
395 });
396 }
397
398 return [response, span];
399 } catch (e) {
400 if (typeof e === "string" || e instanceof Error) {
401 span.recordException(e);
402 }
403
404 span.setStatus({ code: SpanStatusCode.ERROR });
405 span.setAttribute(SEMATTRS_HTTP_STATUS_CODE, 0);
406 span.setAttribute("http.status_text", "This operation was aborted.");
407
408 throw new FetchErrorWithSpan(e, span);
409 }
410};
411
412const calculateRetryDelayForResponse = async (
413 retry: FetchRetryByStatusOptions | undefined,

Callers 1

retryFetchFunction · 0.85

Calls 6

normalizeHttpMethodFunction · 0.85
createFetchAttributesFunction · 0.85
fetchWithInterceptorsFunction · 0.85
startSpanMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…