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?
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'spromise-it-wont-hurt
, for instance), so I figured you might want to illustrate this point?