Documentation Index
Fetch the complete documentation index at: https://mintlify.com/unjs/ofetch/llms.txt
Use this file to discover all available pages before exploring further.
Overview
ofetch throwsFetchError instances when requests fail. These errors provide detailed information about what went wrong, including the request, response, and status information.
FetchError Class
The main error class thrown by ofetch.Error message describing what went wrong
The underlying error that caused this error (error chaining)
IFetchError interface (see below).
Example:
IFetchError Interface
Interface defining the structure of fetch errors.Properties
Always
"FetchError"Error message in format:
[METHOD] "url": status statusText errorMessageThe underlying error that caused this error, if available
The original request URL or Request object
The fetch options used for the request. See FetchOptions.
The response object if available. See FetchResponse.
Parsed response data from
response._dataHTTP status code from the response
HTTP status text from the response
Alias for
statusAlias for
statusTextError Message Format
FetchError messages follow this format:Error Handling
Basic Error Handling
Handling Specific Status Codes
Suppressing Errors
UseignoreResponseError to prevent errors from being thrown:
Using Hooks for Error Handling
Handle errors globally using hooks:Network Errors vs HTTP Errors
Network Errors (triggered inonRequestError):
- Network connectivity issues
- Timeouts
- Aborted requests
- CORS errors
onResponseError):
- 4xx client errors (400, 401, 404, etc.)
- 5xx server errors (500, 502, 503, etc.)
createFetchError
Internal function used to create FetchError instances from a FetchContext.Type Parameters
The type of the response data and error data
Related
- FetchOptions - Request options including
ignoreResponseError - FetchHooks -
onRequestErrorandonResponseErrorhooks - FetchContext - Context passed to error hooks
- FetchResponse - Response interface