We're trying to upgrade an Angular app from 1.5 to 1.6. The app uses ui.bootstrap.modal
extensively and after the upgrade we are seeing the following error thrown whenever that modal is dismissed:
Possibly unhandled rejection: undefined
We've read various SO questions and blog post where people have had the same issue:
- Possibly unhandled rejection when try to dismiss a modal
- Angular 1.6.0: "Possibly unhandled rejection" error
- https://soumen-choudhury.blogspot.com/2017/05/angularjs-possibly-unhandled-rejection.html
The code initially was not catching the rejected promise which explained why we started seeing this error. However, we have since added a catch
after the result
on the $uibModal
and are still seeing the error. Our code now looks like:
$uibModal.open({
templateUrl: 'template.html',
windowClass: 'main-overlay',
controller: 'MyModalController'
}).result
.then(
function (arg) {
// Do something
}
)
.catch(function () {
console.log('I have dismissed the modal');
});
When dismissing the modal, we can see the I have dismissed the modal
text which is the catching of the rejected promise but we also see Possibly unhandled rejection: undefined
.
What is even more weird is that we have a Jasmine test which was failing with exactly the same Possibly unhandled rejection: undefined
error but since adding the catch
in, that is now passing. Only when running the application itself do we see the error now. The important part of the test is:
describe('and cancels the modal', function () {
beforeEach(function () {
deferredConfirmModalAction.reject();
$scope.$apply();
});
it('should not perform the action', function () {
expect(something).not.toHaveBeenCalled();
});
});
Does anyone have idea what the problem could now be? Or how to see more detail about what promise rejection Angular thinks is not being handled?