upstash/context7 · error · Context7Error
network_error
network_error
Error message
errorMessage(cause)
What it means
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.
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
Example fix
// before
const data = await client.exec(cmd);
// after
try {
const data = await client.exec(cmd);
} catch (e) {
if (e instanceof Context7Error && e.code === 'network_error' && e.retryable) {
// retry later or surface connectivity issue; see e.cause
}
} Defensive patterns
Strategy: retry
Validate before calling
null
Try / catch
try {
return await client.exec(cmd);
} catch (e) {
if (e instanceof Context7Error && e.code === 'network_error' && e.retryable) {
// inspect e.cause (ECONNREFUSED/ENOTFOUND/timeout) and retry with backoff
return await withBackoff(() => client.exec(cmd));
}
throw e;
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Failed to fetch
- A fetch implementation is required
- Authentication discovery was redirected. Pass the final…
- Could not reach : )` : ""}\n
- errorBody.error ?? "http_error"
AI-assisted analysis of upstash/context7@4416fb855b (2026-09-16).
Data as JSON: /api/errors/4eb8e70f2ec5f3fb.
Report an issue: GitHub.
Appendix: source
Thrown at packages/sdk/src/http/index.ts:141
const headers =
typeof this.authToken === "function"
? this.headersForToken(await this.authToken())
: this.headersForToken(this.authToken);
if (abortState.signal?.aborted) {
throw abortError(abortState.signal.reason, abortState.timedOut());
}
let response: Response;
try {
response = await this.fetch(url, { ...init, headers });
} catch (cause) {
if (abortState.signal?.aborted) {
throw abortError(cause, abortState.timedOut());
}
if (canRetry && attempt < this.retry.retries) {
await wait(this.retry.backoff(attempt), abortState.signal);
continue;
}
throw new Context7Error(errorMessage(cause), {
code: "network_error",
retryable: true,
cause,
});
}
const metadata = extractResponseMetadata(response, attempt);
this.onResponse?.(metadata);
const shouldRetry =
canRetry && this.retry.statuses.has(response.status) && attempt < this.retry.retries;
if (!shouldRetry) return { response, metadata };
await response.body?.cancel().catch(() => undefined);
await wait(
retryDelay(this.retry.backoff(attempt), metadata.rateLimit?.retryAfter),
abortState.signal
);
}View on GitHub (pinned to 4416fb855b)