angularjs - How to cancel response in interceptor -


how can cancel processing of response if there error code passed? want catch response error code of 500 , prevent custom service request call executing error , success function. want response "stay" in interceptor , not passed custom service success or error callback. how can achieve this? there best practice of "intercepting" responses , handling them globally?

my interceptor has function:

function responseerror( response ) {         switch ( response.status ) {             case 500:                 // cancel processing of response                 // prevent response calling error @ "here" below                 // currently, error function called,                  // when response rejected here                 break;         }          return $q.reject( response );     } 

my backend service has function:

function getjson( url, params ) {         var deferred = $q.defer();         $http( {             url: that.host + url,             method: "get",             params: params || {},             headers: {                 'accept': 'application/json'             }         } ).success( function ( data, status, headers, config ) {             deferred.resolve( data );         } ).error( function ( data ) {             deferred.reject( data );         } ) ;          return deferred.promise;     } 

finally, custom service calls request:

 return backendservice.getjson( "/abc/def", params )                 .then( function ( data ) {                     return data;                 }, function( data ) {                     // here error function should not called, if 500                 } ); 


Comments