Reputation: 1648
In Node.JS, I know that you can use the unhandledRejection
event to catch unhandled errors. However, I only want to catch a certain type of error. How can I do this?
Upvotes: 1
Views: 73
Reputation: 183
From unhandledRejection
node.js docs:
The listener function is called with the following arguments:
reason
| The object with which the promise was rejected (typically an Error object).
p
the Promise
that was rejected.
So, you can check the event reason
... ex.:
if (evt.reason === 'Some specific Error') {
// do something
Upvotes: 1