DoctorV DoctorV - 4 months ago 12x
AngularJS Question

AngularJS Interceptor to Redirect

ExpressJS is sending the following response...


I'm trying to get AngularJS to see this response via an Interceptor and perform a redirect. Does anyone have sample code where Angular catches a server response (such as my "ItemUploaded") and performs a redirect to a partial (via $location)?


Her is the factory for the interceptor.

 .factory('InterceptorService',['$q', '$location', function( $q, $location, $http){
     var InterceptorServiceFactory = {};

     var _request = function(config){
         //success logic her 
         return config;

     var _responseError = function(rejection) {
            //error her for example server respond with 401
         return $q.reject(rejection);
     InterceptorServiceFactory.request = _request;
    InterceptorServiceFactory.responseError = _responseError;
     return InterceptorServiceFactory;


then register the interceptor.

.config(["$httpProvider", function ($httpProvider) {

Every request coming will be passed her.