2016-12-04 147 views
0

我已經對我的產品進行了API調整。出於監控目的,我已安裝logglynewrelicNodeJS Restify嵌套承諾錯誤處理

最近newrelic通知我,在我的代碼中存在錯誤。

app.get('/myroute', (req, res, next) => { 
    let payload = { /*...*/ }; 

    return new Promise((resolve, reject) => { 
    /* some code */ 
    return resolve(); 
    }) 
    .then(/* some promise */) 
    .then(() => { 
     /* some code */ 

     sendEmail({params}); // some error was thrown from one of the promise chain 
           // inside this function... 

     return something; 
    }) 
    .then(/* some promise */) 
    .then(() => { 
     res.send(something); 
    }) 
    .catch(next); 
}); 

諾言鏈解決完美的罰款和用戶得到適當的反應,因爲我沒有回報sendEmail功能。我不想,因爲我不希望用戶長時間等待響應。

function sendMail(params) { 
    return new Promise((resolve, reject) => { 
     /* some code */ 
     return resolve(); 
    }) 
     .then(() => { 
     params.abc.replace('a', 'b'); // error thrown, cannot find replace of undefined. 
     return something; 
     }); 
} 

newrelic抓住了錯誤,但loggly沒有。我已經有了resify的formatters設置,但僅僅這個請求被成功地服務並且不會落入.catch(next)

我不想要一個解決方案來修復sendMail函數。我只是想記錄是否有這樣的錯誤。

反正有沒有把.catch()設置爲sendMail函數來捕獲並記錄這種類型的錯誤?

回答