error handling in asynchronous node.js calls

前端 未结 10 1675
感动是毒
感动是毒 2020-12-12 19:32

I\'m new to node.js although I\'m pretty familiar with JavaScript in general. My question is regarding \"best practices\" on how to handle errors in node.js.

Normall

10条回答
  •  醉话见心
    2020-12-12 19:55

    This is one of the problems with Node right now. It's practically impossible to track down which request caused an error to be thrown inside a callback.

    You're going to have to handle your errors within the callbacks themselves (where you still have a reference to the request and response objects), if possible. The uncaughtException handler will stop the node process from exiting, but the request that caused the exception in the first place will just hang there from the user point of view.

提交回复
热议问题