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

An important Promise rule isn't emphasized #382

Open
tdd opened this issue Jan 25, 2017 · 0 comments
Open

An important Promise rule isn't emphasized #382

tdd opened this issue Jan 25, 2017 · 0 comments

Comments

@tdd
Copy link

tdd commented Jan 25, 2017

Hi Nicholas,

Location: Chapter 11 > Page 230 > "Catching errors" > top code block and text below

There's an important rule in promises, which is that, because resolve and reject callbacks in a single then are never both called, the temptation to put all-catching code in the reject callback alongside a resolve callback is misleading: it wouldn't catch any error from its call-partner resolve callback.

Basically, it's best practice to always put reject callbacks alone on their "own step of the promise chain", be it with .then(null, handler) or the more palatable .catch(handler).

This tricks Promise beginners often enough that it is stressed in most promise tutorials, articles, workshops (including NodeSchool's promise-it-wont-hurt, for instance), so I figured you might want to illustrate this point?

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

1 participant