-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promises with both .then and passed to .all always throw Unhandled rejection Error #493
Comments
Yes it is intended behavior, not handling errors is a bug in the application and that's what you are being made aware of. To handle a rejected promise, you can use a catch handler: promise1()
.then(function () {
console.log('great success');
})
.catch(function(e) {
console.log("handled the error");
}); promise1()
.then(function () {
console.log('great success');
})
.catch(function(e) {
console.log("handled the error");
});
promise1()
.then(function () {
console.log('great success2');
})
.catch(function(e) {
console.log("handled the error");
});
promise1()
.catch(function (err) {
console.log('handled the error');
}); |
Also don't reject with no argument (as that's the same as rejecting with |
To add on to this explanation a bit (Petka, correct any of this if it's wrong):
Here's what's actually happening here:
Here's code that does what you're looking for:
This puts the .then() within the chain containing .catch(). |
This cleared a lot up for me, thanks. |
Hmm so that is why Any way to fix that? It's nicer to write the above instead of |
I seem to be hitting this, too. It would seem that Promise.all is "handling" the rejection, but clearly it's not. I guess that could be documented? |
I am seeing this error with the following structure: new Promise((accept, reject) =>reject("test"))
.then(
() => console.log("ok"),
() => console.log('err')
)
.catch(
(...args) => console.log("wtf", args)
) And I am not seeing this behavior on native Chrome or Firefox promises. What can be going on in here? |
same issue as @cfv1984 |
I'm using async/await and definitely catching my exceptions, but I still get this error. |
Sorry to wake up an old thread, I've this weird issue with jasmine testing framework and bluebird: it sometimes (not consistently) produce errors in the console log like this one:
Those are actually printed in the logs but do not make the test fail. In fact the test succeed, a test exhibiting the issue may look something like this: it('should throw if the check of `type` and `config` throws', () => {
spyOn(actionHandler, 'validateActionConfig').and.returnValue(Promise.reject(new Error('dummy')));
return sut.createAction(principal, action)
.then(() => {
fail('Promise rejection expected, instead fulfilled');
})
.catch((err) => {
expect(actionHandler.validateActionConfig).toHaveBeenCalled();
expect(err.message).toBe('dummy');
});
}); The Furthermore this is not an on/off problem. Some test randomly exhibit this behavior, some never do. I'm not sure if the issue here is on the jasmine or bluebird side. (I also posted this here jasmine/jasmine-npm#124) related dependencies
|
Note: removing the entire catch bloc causes an 'Uncaught (in promise)' error to be thrown in the console (even if the error is handled further up in Promise.all().catch; see: petkaantonov/bluebird#493 ).
I've had this issue for a while and just spent the past day and a half trying to figure out the source of the problem. I've finally narrowed it down.
The following code results in an Unhandled rejection Error:
Is this intended behavior?
The text was updated successfully, but these errors were encountered: