Skip to content

Commit

Permalink
Document the hierarchy of error classes (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
redneb committed Jul 14, 2020
1 parent 61d6f61 commit 559526e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1574,13 +1574,13 @@ const addAccessToken = (accessToken: string): BeforeRequestHook => options => {
Each error contains an `options` property which are the options Got used to create a request - just to make debugging easier.\
Additionaly, the errors may have `request` (Got Stream) and `response` (Got Response) properties depending on which phase of the request failed.
#### got.CacheError
#### got.RequestError
When a cache method fails, for example, if the database goes down or there's a filesystem error.
When a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`. Note that all other types of errors listed below are subclasses of this one, with the exception of `CancelError`.
#### got.RequestError
#### got.CacheError
When a request fails. Contains a `code` property with error class code, like `ECONNREFUSED`.
When a cache method fails, for example, if the database goes down or there's a filesystem error.
#### got.ReadError
Expand All @@ -1590,6 +1590,10 @@ When reading from response stream fails.
When server response code is 2xx, and parsing body fails. Includes a `response` property.
#### got.UploadError
When the request body is a stream and an error occurs while reading from that stream.
#### got.HTTPError
When the server response code is not 2xx nor 3xx if `options.followRedirect` is `true`, but always except for 304. Includes a `response` property.
Expand All @@ -1602,14 +1606,14 @@ When the server redirects you more than ten times. Includes a `response` propert
When given an unsupported protocol.
#### got.CancelError
When the request is aborted with `.cancel()`.
#### got.TimeoutError
When the request is aborted due to a [timeout](#timeout). Includes an `event` and `timings` property.
#### got.CancelError
When the request is aborted with `.cancel()`. This type is not a subclass of `RequestError` as it is re-exported from the `p-cancelable` package.
## Aborting the request
The promise returned by Got has a [`.cancel()`](https://github.com/sindresorhus/p-cancelable) method which when called, aborts the request.
Expand Down

0 comments on commit 559526e

Please sign in to comment.