angularjs - catching 403 errors in angular and showing a pop up -


on our site, predicament transfer project on user. when happens, if original user tries view project he/she transferred, give 403 because no longer owner of project. started interceptors in angular. hooked responseerror see if gets called on 403 so

.config(($httpprovider) => {         $httpprovider.interceptors.push(function() {             return {                 responseerror: function(rejection) {                     console.log("bad response");                     return rejection;                 }             }         });     }); 

so "bad response" gets called , everything, not sure how show modal view or @ point shows error user since 403 response happens on few of our different resources, not projects. thoughts? in advance.

if understand correctly want show error dialog http calls not every call goes through interceptor. try this:-

set config http calls handleerror:true.

$http.get('myurl', {handleerror:true})....   $http.post('myurl',data, {handleerror:true}).... 

etc..

and in interceptor specific config setting display error:-

   $httpprovider.interceptors.push(function() {         return {             responseerror: function(rejection) {                 console.log("bad response");                 if(rejection.config.handleerror && rejection.status === 403){                     //show error dialog                 }                 return rejection;             }         }     }); 

also possibly send status code needs handled well.

 $http.get('myurl', {handlestatus:[403,...]}).... 

and

  $httpprovider.interceptors.push(function() {         return {             responseerror: function(rejection) {                 if((rejection.config.handlestatus || []).indexof(rejection.status) > -1){                     //show error dialog. show in $timeout make async.                 }                 return rejection;             }         }     }); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -