parent
a2bf713e00
commit
a96caf25c5
2 changed files with 14 additions and 0 deletions
|
|
@ -4,6 +4,7 @@
|
|||
- [Signature](#signature)
|
||||
- [How it works](#how-it-works)
|
||||
- [Typical usage](#typical-usage)
|
||||
- [Error handling](#error-handling)
|
||||
- [Loading icons and error messages](#loading-icons-and-error-messages)
|
||||
- [Dynamic URLs](#dynamic-urls)
|
||||
- [Aborting requests](#aborting-requests)
|
||||
|
|
@ -127,6 +128,18 @@ When `m.route` is called at the bottom, the `Todos` component is initialized. `o
|
|||
|
||||
---
|
||||
|
||||
### Error handling
|
||||
|
||||
When a non-`file:` request returns with any status other than 2xx or 304, it rejects with an error. This error is a normal [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) instance, but with a few special properties.
|
||||
|
||||
- `error.message` is set to the raw response text.
|
||||
- `error.code` is set to the status code itself.
|
||||
- `error.response` is set to the parsed response, using `options.extract` and `options.deserialize` as is done with normal responses.
|
||||
|
||||
This is useful in many cases where errors are themselves things you can account for. If you want to detect if a session expired - you can do `if (error.code === 401) return promptForAuth().then(retry)`. If you hit an API's throttling mechanism and it returned an error with a `"timeout": 1000`, you could do a `setTimeout(retry, error.response.timeout)`.
|
||||
|
||||
---
|
||||
|
||||
### Loading icons and error messages
|
||||
|
||||
Here's an expanded version of the example above that implements a loading indicator and an error message:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue