documentation/8-errors.md
Source code:
All Got errors contain various metadata, such as:
code - A string like ERR_NON_2XX_3XX_RESPONSE,options - An instance of Options,request - An instance of Got Stream,response (optional) - An instance of Got Response,timings (optional) - Points to response.timings.Read the article here.
[!NOTE]
- The error codes may differ when the root error has a
codeproperty set.- The root error will be propagated as is via the
causeproperty.
RequestErrorCode: ERR_GOT_REQUEST_ERROR
When a request fails. Contains a code property with error class code, like ECONNREFUSED. All the errors below inherit this one.
CacheErrorCode: ERR_CACHE_ACCESS
When a cache method fails, for example, if the database goes down or there's a filesystem error.
ReadErrorCode: ERR_READING_RESPONSE_STREAM or ERR_HTTP_CONTENT_LENGTH_MISMATCH
When reading from response stream fails.
The error code will be ERR_HTTP_CONTENT_LENGTH_MISMATCH when the strictContentLength option is enabled and the server specifies a content-length header but the actual number of bytes received doesn't match.
ParseErrorCode: ERR_BODY_PARSE_FAILURE
When server response code is 2xx, and parsing body fails. Includes a response property.
UploadErrorCode: ERR_UPLOAD
When the request body is a stream and an error occurs while reading from that stream.
HTTPErrorCode: ERR_NON_2XX_3XX_RESPONSE
When the request is unsuccessful.
A request is successful when the status code of the final request is 2xx or 3xx.
When following redirects, a request is successful only when the status code of the final request is 2xx.
[!NOTE]
304responses are always considered successful.
MaxRedirectsErrorCode: ERR_TOO_MANY_REDIRECTS
When the server redirects you more than ten times. Includes a response property.
UnsupportedProtocolError[!NOTE] This error is not public.
Code: ERR_UNSUPPORTED_PROTOCOL
When given an unsupported protocol.
TimeoutErrorCode: ETIMEDOUT
When the request is aborted due to a timeout. Includes an event (a string) property along with timings.
RetryErrorCode: ERR_RETRYING
Always triggers a new retry when thrown.
AbortErrorCode: ERR_ABORTED
When the request is aborted with AbortController.abort().