2017-03-03 338 views
1

我正在使用connect-timeout模塊。當超時激活時,它似乎將以下錯誤消息轉儲到控制檯:節點連接超時:如何取消「ServiceUnavailableError:Response timeout」日誌消息

ServiceUnavailableError: Response timeout 
    at IncomingMessage.<anonymous> (/app/node_modules/connect-timeout/index.js:75:8) 
    at emitOne (events.js:96:13) 
    at IncomingMessage.emit (events.js:188:7) 
    at Timeout._onTimeout (/app/node_modules/connect-timeout/index.js:48:11) 
    at ontimeout (timers.js:365:14) 
    at tryOnTimeout (timers.js:237:5) 
    at Timer.listOnTimeout (timers.js:207:5) 

如何禁止這些日誌消息?我並不特別想看到它們,因爲超時解僱並不是真的表明存在問題......它只是在做它的工作。這尤其是因爲我可以將我自己的error handling middleware添加到express,可以挑選和選擇與錯誤相關的內容(如果有的話)。

回答

0

你需要抓住這個從快車,代碼應該是這樣的:

function errorHandler (err, req, res, next) { console.log("Oops") } app.use(errorHandler)

欲瞭解更多信息: https://expressjs.com/en/guide/error-handling.html

+0

啊好......我非常接近......我已經已經添加了一個像你一樣的'errorHandler'函數(來測試它正在接收的內容)......事實上,我鏈接到了與您相同的文檔頁面。但是在我的錯誤處理程序中,我有一個'next(err)',我應該把它取出來,否則錯誤會傳遞給股票錯誤處理程序(就像目前那樣),它只會再次記錄消息?可以放棄'next()'以便鏈條停在那裏?股票錯誤處理程序不會做任何其他「聰明」? – drmrbrewer