Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Updated] Document effect of validateStatus on interceptors #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions posts/en/interceptors.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ axios.interceptors.request.use(function (config) {
});

// Add a response interceptor
axios.interceptors.response.use(function (response) {
axios.interceptors.response.use(function onFulfilled(response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
}, function (error) {
}, function onRejected(error) {
// Any status codes that falls outside the range of 2xx cause this function to trigger
// Do something with response error
return Promise.reject(error);
});
```

In normal circumstances the `onFulfilled` response interceptor is only called for responses in the 2xx range, and `onRejected` is called otherwise.
However, this behavior depends on [validateStatus](/docs/req_config).
For instance, if `validateStatus` is setup to always return `true`, then `onFulfilled` will be called for *all* responses.

If you need to remove an interceptor later you can.

```js
Expand All @@ -42,4 +46,4 @@ You can add interceptors to a custom instance of axios.
```js
const instance = axios.create();
instance.interceptors.request.use(function () {/*...*/});
```
```