Skip to content

Commit 76e0d50

Browse files
authored
docs: explain global error handling in interceptors (#453)
* Document global error handling in interceptors Re: #241 (comment) * Remove accidental space
1 parent bec998c commit 76e0d50

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/content/en/helpers.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,22 @@ export default function ({ $axios, redirect }) {
3131
}
3232
```
3333

34+
When intercepting an error, you can return a resolved promise to prevent the error from propagating.
35+
36+
Example: (`plugins/axios.js`)
37+
38+
```js
39+
export default function ({ $axios, error: nuxtError }) {
40+
$axios.onError(error => {
41+
nuxtError({
42+
statusCode: error.response.status,
43+
message: error.message,
44+
});
45+
return Promise.resolve(false);
46+
})
47+
}
48+
```
49+
3450
<alert type="info">
3551

3652
Learn more about [extending axios](/extend)

0 commit comments

Comments
 (0)