chore(docs): fix documentation for usage of interceptors in axios (#6116)

chore(docs): fix documentation for usage of interceptors in axios (#6116)
This commit is contained in:
shravan || श्रvan 2025-01-31 01:19:26 +05:30 committed by GitHub
parent 45d0baa6b3
commit 8889dc0383
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -719,8 +719,11 @@ instance.get('/longRequest', {
You can intercept requests or responses before they are handled by `then` or `catch`.
```js
const instance = axios.create();
// Add a request interceptor
axios.interceptors.request.use(function (config) {
instance.interceptors.request.use(function (config) {
// Do something before request is sent
return config;
}, function (error) {
@ -729,7 +732,7 @@ axios.interceptors.request.use(function (config) {
});
// Add a response interceptor
axios.interceptors.response.use(function (response) {
instance.interceptors.response.use(function (response) {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response;
@ -743,7 +746,8 @@ axios.interceptors.response.use(function (response) {
If you need to remove an interceptor later you can.
```js
const myInterceptor = axios.interceptors.request.use(function () {/*...*/});
const instance = axios.create();
const myInterceptor = instance.interceptors.request.use(function () {/*...*/});
axios.interceptors.request.eject(myInterceptor);
```