{"record":{"id":"4eb8e70f2ec5f3fb","repo":"upstash/context7","slug":"network-error","errorCode":"network_error","errorMessage":"errorMessage(cause)","messagePattern":"errorMessage\\(cause\\)","errorType":"error_code","errorClass":"Context7Error","httpStatus":null,"severity":"error","filePath":"packages/sdk/src/http/index.ts","lineNumber":132,"sourceCode":"    init: RequestInit,\n    method: \"GET\" | \"POST\",\n    abortState: AbortState\n  ): Promise<FetchResult> {\n    const canRetry = method === \"GET\";\n\n    for (let attempt = 0; attempt <= this.retry.retries; attempt++) {\n      let response: Response;\n      try {\n        response = await this.fetch(url, init);\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":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/upstash/context7/blob/80e681a507c5287bc12e483367c40754e29461b9/packages/sdk/src/http/index.ts#L114-L150","documentation":"Context7Error with code \"network_error\" and retryable: true, thrown by fetchWithRetry when the fetch call itself fails (network-level failure, DNS, connection refused, TLS) and retries were exhausted or the error is non-retryable under the retry policy. The message is derived from the underlying cause via errorMessage(cause).","triggerScenarios":"fetch rejects (ECONNREFUSED, ENOTFOUND, ECONNRESET, certificate errors) and either the retry attempts (default 5) are exhausted, the status is not retryable per the retry policy, or a non-AbortError exception is thrown mid-request.","commonSituations":"Server down or wrong port/host in baseUrl, DNS failures, corporate proxy/firewall blocking, IPv6 issues, TLS cert problems, or flaky network in CI.","solutions":["Check the `cause` property of the error for the real underlying failure (ECONNREFUSED, ENOTFOUND, etc.) and fix that root cause.","Verify the baseUrl host/port is reachable (curl the endpoint) and DNS resolves.","Increase retries/backoff in config ({ retry: { retries: 10, backoff: ... } }) for flaky networks.","Since the error is marked retryable, wrap calls in your own retry-with-backoff loop for critical operations.","Check firewall/proxy/VPN settings and TLS certificates."],"exampleFix":"// before\nconst data = await client.exec(cmd); // throws on transient network blips after 5 attempts\n// after\ntry {\n  const data = await client.exec(cmd);\n} catch (e) {\n  if (e instanceof Context7Error && e.code === 'network_error') {\n    console.error('Network failure, cause:', e.cause); // inspect root cause\n  }\n  throw e;\n}","handlingStrategy":"retry","validationCode":"// Pre-flight reachability check\nconst ok = await fetch(new URL('/health', baseUrl), { method: 'HEAD' }).then(r => r.ok).catch(() => false);\nif (!ok) throw new Error(`Context7 endpoint ${baseUrl} unreachable`);","typeGuard":"function isNetworkError(e: unknown): e is Context7Error {\n  return e instanceof Context7Error && e.code === 'network_error' && e.retryable === true;\n}","tryCatchPattern":"for (let i = 0; i < 3; i++) {\n  try {\n    return await client.exec(cmd);\n  } catch (e) {\n    if (!isNetworkError(e) || i === 2) throw e;\n    await new Promise(r => setTimeout(r, 2 ** i * 250));\n  }\n}","preventionTips":["Inspect err.cause for the root socket/DNS/TLS failure before changing app code.","Keep the default retry policy enabled for production workloads.","Verify baseUrl reachability in CI before running test suites.","Watch for VPN/proxy changes that break corporate network egress."],"tags":["network","retry","http"],"backgroundTag":"network-request-failed","analyzedSha":"80e681a507c5287bc12e483367c40754e29461b9","analyzedAt":"2026-09-08T05:18:41.043Z","contentChangedAt":"2026-09-08T05:18:41.043Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}