日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

nodejs中处理回调函数的异常

發布時間:2024/7/19 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nodejs中处理回调函数的异常 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

假設是使用nodejs+express3這個經典的組合。那么有一種非常方面的處理回調函數異常的方法:


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 }));

轉載于:https://www.cnblogs.com/gccbuaa/p/6929827.html

總結

以上是生活随笔為你收集整理的nodejs中处理回调函数的异常的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。