1
我正在用NodeJS和Express構建一個應用程序,並最近在Raygun中加入了錯誤處理。如何在使用Raygun的快遞處理程序後關閉我的流程?
Raygun提供了一個專門用於Express的錯誤處理程序,但它必須是運行的最後一件中間件。現在,我有:
//Log the domain id, req, and error to the console
app.use(function errorHandler(err, req, res, next) {
console.log('error on request %d %s %s: %s', process.domain.id, req.method, req.url, err)
next(err)
})
//Log the error to Raygun
//!Must be last piece of middleware to be defined
app.use(raygunClient.expressHandler);
但問題是,服務器繼續運行,潛在地使應用程序處於未知狀態。我想做一個優雅的服務器關機,但如果我添加
//Shuts down the process
app.use(function errorHandler(err, req, res, next) {
process.exit()
})
然後Raygun的快速處理程序不起作用。
什麼?
啊!應該只查看源代碼。沒有意識到expressHandler是如此基本。 – tcmoore