Possibly unhandled rejection in Angular 1.6

前端 未结 9 1581
轻奢々
轻奢々 2020-12-06 04:31

I have a code with AngularJS:

service.doSomething()
  .then(function(result) {
      //do something with the result
  });

In AngularJS 1.5.

9条回答
  •  余生分开走
    2020-12-06 04:55

    errorOnUnhandledRejections(false); was not a resolution for me.

    You do indeed need to define an exception handler... however... wrap it in a timeout function: this will force the original exception/stack trace to be thrown.

    To make the error show up as an error in the web console, as you originally intended:

    ng.factory('$exceptionHandler', function($log) {
      return function(exception, cause) {
        // do some some stuff...
        setTimeout(function(){
          // throw the original exception (with correct line #'s etc)
          throw exception;
        })
      };
    });
    

    Heres the timeout trick: Why can I not throw inside a Promise.catch handler?

提交回复
热议问题