In Node.js 7 what is the proper way to suppress UnhandledPromiseRejectionWarning?

后端 未结 4 942
谎友^
谎友^ 2021-01-04 10:26

In Node.js I have a module which consists of just one function. The function returns promise and the promise could be rejected. Still I don\'t want to force all users of the

4条回答
  •  梦谈多话
    2021-01-04 10:46

    I can't figure out any way to do what you're describing.

    If you don't care about passing errors to your users, you can add a dummy catch block on the end of your promise chain:

    Promise.reject('foo')
    .catch(() => {})
    

    This will silence the warning, but won't allow your users to handle the error.

    Perhaps you could add an option that your users could decide if they want to handle the error or not.

提交回复
热议问题