0

I am relatively new to angular so I am not sure if I am missing something here.

I have an Http Interceptor for adding JWT tokens to requests as well as handling responses from the server.

.factory('myHttpInterceptor', ['$q', '$location', '$window', function($q, $location, $window) {
   return {
       request: function(request) {
           console.log('myHttpInterceptor - request');
           return request;
       },
       requestError: function(requestError) {
           console.log('myHttpInterceptor - requestError');
           return requestError;
       },
       response: function(response) {
           console.log('myHttpInterceptor - response');
           return response;
       },
       responseError: function(responseError) {
           console.log('myHttpInterceptor - responseError');
           return responseError;
       }
   };
}]);


//Http Intercpetor to check auth failures 
angular.module("POSMobile").config(['$httpProvider', function($httpProvider) {
   $httpProvider.interceptors.push('myHttpInterceptor');
}]);

So here is the problem, I am trying to handle a 401 Unauthorized error by changing the route to my login screen however the responseError listener doesn't ever seem to fire.

I have checked my iis logs and my service is definitely returning a 401 code

Here I did a test using Postman and picked up the 401Screenshot of Postman

However in my interceptor it evaluates like so xdk debug screenshot

and finally after the request is completed I get a 401 error in the debug console

Thanks in advance

DanielRSA
  • 15
  • 1
  • 3

2 Answers2

0
.factory('myHttpInterceptor',['$q','$location',function($q,$location) {
    return {
            responseError: function(response){
            console.log(response.status+' intercepted');
            return $q.reject(response);
           }
         };
     }]);

can you try this.

Denny John
  • 464
  • 7
  • 20
0

Try clearing the data for the app on the device you are using to test

NEhlers
  • 16