Skip to content

Errors ​

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 exceeded timeoutMstimeoutMs
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.

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.