Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Rejected promises don't get handled by $exceptionHandler #11754

Closed
bblack opened this issue Apr 28, 2015 · 2 comments
Closed

Rejected promises don't get handled by $exceptionHandler #11754

bblack opened this issue Apr 28, 2015 · 2 comments

Comments

@bblack
Copy link

bblack commented Apr 28, 2015

Possibly related to #7992 .

Given this app:

var app = angular.module('plunker', []);
app.factory('$exceptionHandler', function(){
  return function(exception, context){
    console.log('$exceptionHandler caught', exception)
  }
})
app.controller('MainCtrl', function($scope, $q) {
  $scope.name = 'World';

  var d = $q.defer();
  d.reject(666);

  var d2 = $q.defer();
  d2.resolve(true);
  d2.promise.then(function(){
    throw new Error('thrown in then')
  })
});

$exceptionHandler only gets the error that was thrown in the d2 chain, not the explicit rejection reason for d. I can't find documentation stating that this is or is not desired behavior, but such a case is captured in Bluebird promises, for example. It would also be cumbersome to have to add a .catch($exceptionHandler) on every single promise in one's project.

@petebacondarwin
Copy link
Contributor

I think this is related to #7992, which does appear to have been resolved yet.

From a quick read through it looks like what we want is for errors to be reported to $exceptionHandler only if there is no rejected handler registered for a promise chain. Is that right?

@caitp can you take a look and see if we can get to an acceptable solution. If it is agreed that such a solution is not a breaking change then it could get into a later 1.4.x release but it is not going to get into 1.4.0. Otherwise we can look to get it into 1.5.0

@gkalpak
Copy link
Member

gkalpak commented May 13, 2016

Fixed with #13662. Will be available on v1.6.x.

@gkalpak gkalpak closed this as completed May 13, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants