nodejs中处理回调函数的异常
生活随笔
收集整理的這篇文章主要介紹了
nodejs中处理回调函数的异常
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
假設(shè)是使用nodejs+express3這個經(jīng)典的組合。那么有一種非常方面的處理回調(diào)函數(shù)異常的方法:
1. 安裝模塊:express-domain-middleware
2. 增加例如以下的代碼:
app.use(require('express-domain-middleware')); app.use(function errorHandler(err, req, res, next) {logger.error('error on request %d %s %s: %j', process.domain.id, req.method, req.url, err);res.send(500, "there is an error in callback function");if(err.domain) {//you should think about gracefully stopping & respawning your server//since an unhandled error might put your application into an unknown state} }); app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));轉(zhuǎn)載于:https://www.cnblogs.com/gccbuaa/p/6929827.html
總結(jié)
以上是生活随笔為你收集整理的nodejs中处理回调函数的异常的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: codeforces 264 B. Go
- 下一篇: Spark笔记——技术点汇总