Node.JS - 处理某些类型的承诺拒绝?

Node.JS - Handling Certain Types of Promise Rejections?

在 Node.JS 中,我知道您可以使用 unhandledRejection 事件来捕获未处理的错误。但是,我只想捕获某种类型的错误。我该怎么做?

来自 unhandledRejection node.js docs:

使用以下参数调用侦听器函数:

reason |承诺被拒绝的对象(通常是错误对象)。

p Promise 被拒绝了。

因此,您可以检查事件 reason... 例如:

 if (evt.reason === 'Some specific Error') {
 // do something