Proposal: Conditional `catch` in Promises
Ayush Gupta
ayushg3112 at gmail.com
Tue Apr 24 09:35:39 UTC 2018
I propose that in `Promises`, we accept another function which returns a
`boolean` as an argument to `catch`. It will enable us to write code like
this:
```js
return somePromise
.catch((reason) => reason instanceof ValidationError, reason =>
handleValidationError(reason)) // handle ValidationErrors
.catch((reason) => reason instanceof InternalError, reason =>
handleInternalError(reason)) // handle InternalErrors
.catch(reason => handleOtherErrors(reason)) // catch all others
```
If the passed function evaluates to `true`, call the actual rejection
handler. If none of the catch are eligible to handle the rejection, it
causes an unhandled rejection.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180424/512fc72d/attachment-0001.html>
More information about the es-discuss
mailing list