I created an AngularJS website working with an API. This API provides several functions, such as authentication (Oauth).
When the API returns error 401, this means that the access_token expired and needs to be updated with refresh_token .
I created an interceptor in AngularJS. Its purpose is to check whether the result returned by the API is a 401 error, and if that happens, it should update the token and then process the previous rejected request.
The problem is that the interceptor creates an infinite loop. After the second failure of the initial request, it should stop, but this is not so.
angular.module('myApp') .factory('authInterceptor', function ($rootScope, $q, $window, $injector) { return {
So this code:
- Starts when the first request is not executed.
- Updates token
- Repeats the request but fails again (<- I just want to stop it here)
- Updates token
- Repeats the request but does not work again
- Updates token
- Repeats the request but does not work again
- etc...
source share