Open quchwe opened 6 years ago
hi. i used this approach, i don't know if it's the best
$httpProvider.interceptors.push(function ($q, $rootScope, $cookies, env, $injector) { let errorNotify = (err) => { var Notification = $injector.get('Notification'); if(err.error && angular.isArray(err.error)){ angular.forEach( err.error, (text) => { if(text.indexOf('_') !== -1) text = text.replace(/_/g, ' '); Notification.error(text); }) } else if(err.error){ Notification.error(err.error); } else if(err) { Notification.error(err); } } return { . . . 'responseError': function (rejection) { if (parseInt(rejection.status) === 401) { $rootScope.$emit('unauthorized'); } if (parseInt(rejection.status) === 500) { errorNotify('Server Error. Please try again later.'); } return $q.reject(rejection); } }
hi. i used this approach, i don't know if it's the best