upstash/context7 · error · Context7Error

request_aborted

request_aborted

Error message

Request was aborted (or "Request timed out" when timedOut)

What it means

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().

Solutions

  1. Check that any AbortSignal you pass is not already aborted at call time; create a fresh AbortController per request.
  2. Raise or remove the timeout option if requests legitimately need more time.
  3. Handle code === "request_aborted" distinctly from network errors and distinguish timedOut via the message.
  4. If aborting on unmount, only abort after the request has actually been started, or guard the call.

Example fix

// before
const controller = new AbortController();
controller.abort();
await client.request({ path: '/x', signal: controller.signal }); // throws request_aborted
// after
const controller = new AbortController();
await client.request({ path: '/x', signal: controller.signal });
controller.abort();
Defensive patterns

Strategy: try-catch

Validate before calling

function assertNotAborted(signal?: AbortSignal) { if (signal?.aborted) throw new Error('signal already aborted before request'); }
assertNotAborted(signal);

Type guard

const isAbortError = (e: unknown): e is { code: 'request_aborted'; message: string } =>
  typeof e === 'object' && e !== null && (e as any).code === 'request_aborted';

Try / catch

try {
  await client.request({ path, signal, timeout: 30000 });
} catch (e) {
  if (e.code === 'request_aborted') {
    const timedOut = e.message.includes('timed out');
    // handle cancel vs timeout
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Request timed out: what client-side request timeouts mean across libraries (Request timed out, TIMED_OUT, APITimeoutError) — this error's family across 39 libraries.

Related errors


AI-assisted analysis of upstash/context7@4416fb855b (2026-09-16). Data as JSON: /api/errors/fbf6fad041619983. Report an issue: GitHub.

Appendix: source

Thrown at packages/sdk/src/http/index.ts:79

    this.headers = { "Content-Type": "application/json", ...config.headers };
    this.authToken = config.authToken;
    if (!config.fetch && !globalThis.fetch) {
      throw new TypeError("A fetch implementation is required");
    }
    this.fetch = config.fetch ?? globalThis.fetch.bind(globalThis);
    this.onResponse = config.onResponse;
    this.retry = createRetryPolicy(config.retry);
  }

  public async request<TResult>(request: Context7Request): Promise<Context7Response<TResult>> {
    const method = request.method ?? "POST";
    const abortState = createAbortState(
      [resolveSignal(this.options.signal), request.signal],
      request.timeout ?? this.options.timeout
    );
    try {
      if (abortState.signal?.aborted) {
        throw abortError(abortState.signal.reason, abortState.timedOut());
      }

      const init: RequestInit = {
        cache: normalizeCache(request.cache ?? this.options.cache),
        method,
        body: request.body === undefined ? undefined : JSON.stringify(request.body),
        keepalive: this.options.keepAlive,
        signal: abortState.signal,
      };

      const { response, metadata } = await this.fetchWithRetry(
        buildUrl(this.baseUrl, method, request),
        init,
        method,
        abortState
      );
      if (!response.ok) {
        await throwResponseError(

View on GitHub (pinned to 4416fb855b)