Error: Interceptor not triggered
See original GitHub issueHere is my interceptor
axios.interceptors.response.use((response) => {
return response
}, function (error) {
// Do something with response error
if (error.response.status === 401) {
auth.logout()
router.replace('/login')
}
return Promise.reject(error)
})
During this call which returns a 401, the interceptor is not triggered. I can catch the reject() where I called method.
axios.get('/api/employees/')
.then(response => {
commit('SET_EMPLOYEE_LIST', response.data)
resolve(response)
})
.catch(err => reject(err))
- axios version: v0.16.2
- Environment: chrome 59, windows 10
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Interceptor not intercepting http requests (Angular 6)
In my case interceptor wasn't getting involved for service calls because I had imported HttpClientModule multiple times, for different ...
Read more >Interceptor not triggering error function on 401 response #5120
I'm trying to do this by checking if I receive a 401 response, if that was caused by an expired token, and if...
Read more >That's why your Angular Interceptor may NOT WORK! [5 ...
EDIT: This problem does not occur when you import HttpClientModule only ONCE in the AppModule or CoreModule (and import the CoreModule into ...
Read more >Angular - handle HTTP errors using interceptors
An error interceptor is a special type of interceptor which is used for handling errors that arise while making an HTTP request. The...
Read more >HTTP Requests and Error Handling with Angular Interceptors
Create a folder called error-dialog in the app folder. · Create a service for errors called errorDialogService in a file called errordialog.service.ts. ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I have had a similar issue, it seems like the axios instance is different when the interceptor is added and when a call is performed.
You also probably want to have a better handling of the 401 in the interceptor.
I found a workaround for the not triggered interceptor although it is probably a bug, I add the interceptor to the instance itself:
This is weird. In all the tutorials and SE answers, I see the interceptor being added to the axios instance. But this didn’t work for me at all. Instead, I had to add it to the imported axios module before calling the
create()
method: