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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -