2016-03-11 59 views
0

我有一個關於節點JS當uncaughtException發生

我將發送自動郵件開發商,如果事情在服務器上發生的導致服務器停止工作設置的方法(錯誤代碼正常關閉的問題節點JS安裝消息或等)。

這些都是我的代碼

process.on('uncaughtException', function (err) { 
    console.error((new Date).toUTCString() + ' uncaughtException:', err.message); 
    console.error(err.stack); 
    //Mandrill 
     ... 
    }); 
}); 

我的電子郵件有什麼亮點是隻有這些

TypeError: Cannot read property 'x' of undefined

,但我要的是我想包括在這樣的郵件日誌

TypeError: Cannot read property 'x' of undefined 
at ...\routes\v3\users.js:57:20 
    at ...\node_modules\mongoose-deep-populate\lib\plugin.js:81:11 
    at nextLevel (...\node_modules\mongoose-deep-populate\lib\plugin.js:237:36) 
    at Promise.one (...\node_modules\mongoose-deep-populate\lib\plugin.js:232:27) 
    at Promise.<anonymous> (...\node_modules\mongoose\node_modules\mpromise\lib\promise.js:177:8) 
    at Promise.emit (events.js:107:17) 
    at Promise.emit (...\node_modules\mongoose\node_modules\mpromise\lib\promise.js:84:38) 
    at Promise.fulfill (...\node_modules\mongoose\node_modules\mpromise\lib\promise.js:97:20) 
    at Promise.resolve (...\node_modules\mongoose\lib\promise.js:114:23) 
    at ...\node_modules\mongoose\lib\model.js:2051:23 

有幫助嗎?謝謝

回答

1

我也發郵件給自己錯誤的情況下出現錯誤。我的代碼是

module.exports = function(error, req, res, next){ 
    if(error){ 
    var body = '<h3>Error stack </h3>'+ error.stack; 
    sendMail(['[email protected]'],'Ha Ha 500',body.replace(/(?:\r\n|\r|\n)/g, '<br />')) // replece function for formatting, sendMail() sends mail through amazon ses 
    } 
    } 

這裏是郵件的篩網拍攝 enter image description here

+0

的作品就像一個魅力對我來說,非常感謝! –