diff --git a/posts/en/interceptors.md b/posts/en/interceptors.md index 1d3b052..2b2ee09 100644 --- a/posts/en/interceptors.md +++ b/posts/en/interceptors.md @@ -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 @@ -42,4 +46,4 @@ You can add interceptors to a custom instance of axios. ```js const instance = axios.create(); instance.interceptors.request.use(function () {/*...*/}); -``` \ No newline at end of file +```