AngularJS global error handling - custom method error handler doesn't fire -
here's scenario (angularjs v1.3.15):
$httpprovider.interceptors.push(function($rootscope) { return { 'responseerror': function(rejection) { //...some custom data checking console.log('error #1'); return rejection; } }; });
and now, send query server using $resource
(which returns 404 error, desired in case), , return $promise
:
var promise = controller.sendcustomquery(); promise.catch(function (response) { console.log('error #2'); } );
and in console can see message error #1
, no error #2
. why ?
instead of returning rejection return rejected promise
angular.module('app', []) .config(function($httpprovider) { $httpprovider.interceptors.push(function($q) { return { responseerror: function(rejection) { console.log('error #1') return $q.reject(rejection) } } }) }) .run(function($http) { $http.get('some/error/path').catch(function() { console.log('error #2') }) })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script> <div ng-app='app'> </div>
Comments
Post a Comment