Skip to content
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

Chained function gets called even if previous operation failed #2

Open
ideadapt opened this issue Dec 30, 2017 · 0 comments
Open

Chained function gets called even if previous operation failed #2

ideadapt opened this issue Dec 30, 2017 · 0 comments

Comments

@ideadapt
Copy link

ideadapt commented Dec 30, 2017

sendEIAToProxy is called, even if importKey has failed. (If this is intended behaviour, just ignore this issue :).) Thats because the first error handler returns undefined, which ends up in a resolved promise being returned at the end of line 97, which leads to execution of success handler (sendEIAToProxy).

.then(sendEIAToProxy, (x) => { console.log('Error encrypting IA!', x); });

To mitigate this, you could:

  • use .catch(errorHandler) (not Promise/A+ compliant)
  • .then(null, errorHandler)

at the end of the then chain.

One line of code tells more than any prosa:

Promise.reject("some err").then(null, (...a)=>console.log("errhandler1", ...a)).then((...a)=>console.log("success2", ...a), (...a)=>console.log("errhandler2", ...a))

Its recommended to always have a final error handler at the end. This prevents possibly uncaught promise rejections.

@benleb benleb self-assigned this Jan 3, 2018
@benleb benleb removed their assignment Jul 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants