Proposal: Conditional `catch` in Promises

Ayush Gupta ayushg3112 at
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

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: <>

More information about the es-discuss mailing list