Skip to content

Errors ​

Documentation for 2.7.x

This documents rust-fetch 2.7.x. For the latest version, see the current documentation. The changelog lists what 2.8 added.

Every rejection is an Error whose name and kind are one of:

kindWhenExtra fields
HttpErrorNon-2xx responsestatus, statusText, body (full response body as text)
TimeoutErrorAn attempt, phase timer or logical deadline expiredtimeoutMs, phase (connect, response, idle, total)
CircuitOpenErrorOpt-in circuit breaker refused the attemptorigin, retryAfterMs
NetworkErrorDNS, connection, TLS or CORS failure, a body cut off mid-transfer, a WebSocket that fails to connect or drops, or a limit you setThe limit that was reached, when one was: maxResponseBytes, maxPendingRequests, maxLineBytes, maxEventBytes, maxQueuedMessages or maxQueuedBytes
CancelledErrorThe signal was aborted
InvalidInputErrorBad URL, method, header, option or body. Rejected before anything is sent.parameter
ParseErrorresponseType: 'json' and the body isn't JSON
JsInteropErrorUnexpected JS ↔ Wasm conversion failure
js
try {
  await client.get('/users/9');
} catch (error) {
  if (error.kind === 'HttpError' && error.status === 404) {
    // not found
  } else if (error.kind === 'TimeoutError') {
    console.warn(`gave up after ${error.timeoutMs} ms`);
  } else {
    throw error;
  }
}

With a retry budget, an error whose retry the budget refused also has retryBudgetExhausted: true, whatever its kind.

Request errors also carry method, url and attempts (zero for validation failures). The URL identifies the last destination known to the transport and includes query strings unless you configure redactUrl. Opt-in observability adds timings and preserves an underlying JavaScript cause where available. SSE and WebSocket errors carry connection context too.

Long error bodies (such as an HTML error page) are truncated to 200 characters in message. error.body always has the full text.

Released under the MIT or Apache-2.0 license.