I have a code with AngularJS:
service.doSomething()
.then(function(result) {
//do something with the result
});
In AngularJS 1.5.
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?