Skip to content

Error API ​

ts
import { createFetchError, isFetchError, isAbortError } from 'tanstack-fetch'

FetchError ​

FieldMeaning
statusHTTP status (0 for network)
codeMachine-readable code when available
messageHuman message
bodyParsed error body (raw text when not valid JSON)
headersResponse headers when present

Guards ​

  • isFetchError(error) — narrow thrown HTTP / transport errors
  • isAbortError(error) — aborted signals (AbortError) and timeoutMs timeouts (TimeoutError)

Timeouts and aborts are not FetchErrors and do not run onRequestError interceptors.

Codes ​

codeWhen
from bodyNon-2xx response whose JSON body has a string code
HTTP_ERRORAny other non-2xx response (incl. non-JSON bodies)
PARSE_ERROR2xx response with an invalid JSON body
NETWORK_ERRORConnection failed (status: 0)
RETRY_EXHAUSTEDInterceptors kept asking to retry past maxRetries

MIT Licensed · Created by Mohammad Garmabi · Not an official TanStack package