{"record":{"id":"4eb8e70f2ec5f3fb","repo":"upstash/context7","slug":"network-error","errorCode":"network_error","errorMessage":"errorMessage(cause)","messagePattern":"errorMessage\\(cause\\)","errorType":"exception","errorClass":"Context7Error","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/http/index.ts","lineNumber":141,"sourceCode":"      const headers =\n        typeof this.authToken === \"function\"\n          ? this.headersForToken(await this.authToken())\n          : this.headersForToken(this.authToken);\n      if (abortState.signal?.aborted) {\n        throw abortError(abortState.signal.reason, abortState.timedOut());\n      }\n      let response: Response;\n      try {\n        response = await this.fetch(url, { ...init, headers });\n      } catch (cause) {\n        if (abortState.signal?.aborted) {\n          throw abortError(cause, abortState.timedOut());\n        }\n        if (canRetry && attempt < this.retry.retries) {\n          await wait(this.retry.backoff(attempt), abortState.signal);\n          continue;\n        }\n        throw new Context7Error(errorMessage(cause), {\n          code: \"network_error\",\n          retryable: true,\n          cause,\n        });\n      }\n\n      const metadata = extractResponseMetadata(response, attempt);\n      this.onResponse?.(metadata);\n      const shouldRetry =\n        canRetry && this.retry.statuses.has(response.status) && attempt < this.retry.retries;\n      if (!shouldRetry) return { response, metadata };\n\n      await response.body?.cancel().catch(() => undefined);\n      await wait(\n        retryDelay(this.retry.backoff(attempt), metadata.rateLimit?.retryAfter),\n        abortState.signal\n      );\n    }","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/upstash/context7/blob/4416fb855b8f752be735e34f943b5d0762701aad/packages/sdk/src/http/index.ts#L123-L159","documentation":"fetchWithRetry wraps low-level network failures (fetch rejections, connection errors, aborted requests that are not user aborts) in a Context7Error with code network_error and retryable: true, using errorMessage(cause) as the message. After retries are exhausted — or when the failure is not retryable — the underlying cause is rethrown as this wrapped error.","triggerScenarios":"Network-level failures during a request: DNS resolution failure, connection refused/reset, TLS errors, socket hang-up, or the request timing out after all retry attempts have been consumed (canRetry false or attempt === retry.retries).","commonSituations":"Offline or flaky network; VPN/firewall blocking the API host; wrong baseUrl pointing at a closed port; server downtime; corporate proxy intercepting TLS; sustained outages that exhaust the retry budget.","solutions":["Check network connectivity and that the API host is reachable (curl the baseUrl)","Verify baseUrl/DNS/proxy settings are correct","Since the error is retryable: re-run the request with backoff, or increase the retry policy (retries/backoff) in client config","Inspect error.cause for the original failure (ECONNREFUSED, ENOTFOUND, TLS, timeout) to pinpoint the root problem"],"exampleFix":"// before\nconst data = await client.exec(cmd);\n// after\ntry {\n  const data = await client.exec(cmd);\n} catch (e) {\n  if (e instanceof Context7Error && e.code === 'network_error' && e.retryable) {\n    // retry later or surface connectivity issue; see e.cause\n  }\n}","handlingStrategy":"retry","validationCode":"null","typeGuard":null,"tryCatchPattern":"try {\n  return await client.exec(cmd);\n} catch (e) {\n  if (e instanceof Context7Error && e.code === 'network_error' && e.retryable) {\n    // inspect e.cause (ECONNREFUSED/ENOTFOUND/timeout) and retry with backoff\n    return await withBackoff(() => client.exec(cmd));\n  }\n  throw e;\n}","preventionTips":["Configure a retry policy (retries/backoff) suited to your environment's network reliability","Monitor e.cause codes to distinguish DNS, connection, and TLS problems","Health-check the API host at startup and circuit-break during outages","Set a sane timeout so hangs become retryable network errors instead of infinite waits"],"tags":["network","http","retry","fetch"],"backgroundTag":"network-request-failed","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"}