There can be two categories of errors in a promise chain.
- Mistakes coming from the promise chain (using
.catch) - Mistakes in setting up a promise chain
My question is how best to deal with the latter.
For example, the following .catchwill not catch exceptions thrown foobefore he has the opportunity to return a promise.
function go() {
return foo()
.then(bar)
.catch(bam);
}
Clearly, I can wrap the contents goin a block try-catch.
But would it be better to return the immediately rejected promise from the catch block footo “API support” and have a promise-based interface for all possible events?
source
share