I am using axios interceptors to log all the api errors to a backend server at one mon place. The problem is, if one api call fails the logError function is called multiple times and multiple duplicate requests were sent for logging.
Here's my code
axios.interceptors.response.use(response => {
return response;
},
error => {
logError(error.message);
return Promise.reject(error);
})
I am using axios interceptors to log all the api errors to a backend server at one mon place. The problem is, if one api call fails the logError function is called multiple times and multiple duplicate requests were sent for logging.
Here's my code
axios.interceptors.response.use(response => {
return response;
},
error => {
logError(error.message);
return Promise.reject(error);
})
Share
Improve this question
asked Aug 6, 2020 at 6:52
Sathish Kumar SekarSathish Kumar Sekar
111 silver badge4 bronze badges
2
- 1 Where is your interceptor added? If it's inside a function that is always called (or multiple times called), that should be the problem. Please provide more code regarding this interceptor that you're using. – Mihai Moraru Commented Aug 6, 2020 at 7:52
- Interceptor code is added in app.js file which will be rendered only once. Also, this is happening only when the backend api is throwing error. I see multiple interceptor calls happening at a time. – Sathish Kumar Sekar Commented Aug 6, 2020 at 8:46
1 Answer
Reset to default 8This might be issue that your interceptor code initialized multiple times, I was facing the same issue and when it initialized once, solved the issue.