{"record":{"id":"fbf6fad041619983","repo":"upstash/context7","slug":"request-aborted","errorCode":"request_aborted","errorMessage":"Request was aborted (or \"Request timed out\" when timedOut)","messagePattern":"Request was aborted \\(or \"Request timed out\" when timedOut\\)","errorType":"exception","errorClass":"Context7Error","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/http/index.ts","lineNumber":79,"sourceCode":"    this.headers = { \"Content-Type\": \"application/json\", ...config.headers };\n    this.authToken = config.authToken;\n    if (!config.fetch && !globalThis.fetch) {\n      throw new TypeError(\"A fetch implementation is required\");\n    }\n    this.fetch = config.fetch ?? globalThis.fetch.bind(globalThis);\n    this.onResponse = config.onResponse;\n    this.retry = createRetryPolicy(config.retry);\n  }\n\n  public async request<TResult>(request: Context7Request): Promise<Context7Response<TResult>> {\n    const method = request.method ?? \"POST\";\n    const abortState = createAbortState(\n      [resolveSignal(this.options.signal), request.signal],\n      request.timeout ?? this.options.timeout\n    );\n    try {\n      if (abortState.signal?.aborted) {\n        throw abortError(abortState.signal.reason, abortState.timedOut());\n      }\n\n      const init: RequestInit = {\n        cache: normalizeCache(request.cache ?? this.options.cache),\n        method,\n        body: request.body === undefined ? undefined : JSON.stringify(request.body),\n        keepalive: this.options.keepAlive,\n        signal: abortState.signal,\n      };\n\n      const { response, metadata } = await this.fetchWithRetry(\n        buildUrl(this.baseUrl, method, request),\n        init,\n        method,\n        abortState\n      );\n      if (!response.ok) {\n        await throwResponseError(","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/sdk/src/http/index.ts#L61-L97","documentation":"The HTTP client throws a Context7Error with code \"request_aborted\" before sending a request when one of the caller-provided signals is already aborted or the configured timeout has elapsed. The message becomes \"Request timed out\" when abortState.timedOut() is true, otherwise \"Request was aborted\". This is the fail-fast path of request().","triggerScenarios":"Calling request() (directly or through the SDK client) with an AbortSignal that is already aborted, or with timeout: 0 / an elapsed timeout, so abortState.signal?.aborted is true before fetch is invoked.","commonSituations":"Passing a controller.signal after abort() was called for an earlier request; a very small timeout value; reusing a request object whose signal was aborted by a previous attempt; component unmount aborting a signal before the call runs.","solutions":["Check that any AbortSignal you pass is not already aborted at call time; create a fresh AbortController per request.","Raise or remove the timeout option if requests legitimately need more time.","Handle code === \"request_aborted\" distinctly from network errors and distinguish timedOut via the message.","If aborting on unmount, only abort after the request has actually been started, or guard the call."],"exampleFix":"// before\nconst controller = new AbortController();\ncontroller.abort();\nawait client.request({ path: '/x', signal: controller.signal }); // throws request_aborted\n// after\nconst controller = new AbortController();\nawait client.request({ path: '/x', signal: controller.signal });\ncontroller.abort();","handlingStrategy":"try-catch","validationCode":"function assertNotAborted(signal?: AbortSignal) { if (signal?.aborted) throw new Error('signal already aborted before request'); }\nassertNotAborted(signal);","typeGuard":"const isAbortError = (e: unknown): e is { code: 'request_aborted'; message: string } =>\n  typeof e === 'object' && e !== null && (e as any).code === 'request_aborted';","tryCatchPattern":"try {\n  await client.request({ path, signal, timeout: 30000 });\n} catch (e) {\n  if (e.code === 'request_aborted') {\n    const timedOut = e.message.includes('timed out');\n    // handle cancel vs timeout\n  }\n  throw e;\n}","preventionTips":["Create a fresh AbortController for every request.","Never reuse an already-aborted signal.","Set a realistic timeout for slow endpoints.","Abort only when cancellation is truly intended (e.g. on unmount)."],"tags":["timeout","abort","http","network"],"backgroundTag":"request-timeout","analyzedSha":"4416fb855b8f752be735e34f943b5d0762701aad","analyzedAt":"2026-09-16T20:28:07.148Z","contentChangedAt":"2026-09-16T20:28:07.148Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}