2016-12-04 4 views
0

내 제품에 대한 API를 만들었습니다. 모니터링 목적으로 logglynewrelic을 설치했습니다.NodeJS 중첩 된 약속 오류 처리 처리

최근에 newrelic은 내 코드 어딘가에 오류가 있음을 알립니다. 내가하지 반환sendEmail 기능을했기 때문에

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

는 약속 체인은 적절한 응답을 얻을 완벽하게 정상적으로 및 사용자 해결. 그리고 내가 원하지 않는 이유는 사용자가 오랫동안 응답을 기다리지 않기 때문입니다.

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하지 않았다. 이미 restoir의 formatters 설정이 있지만 요청이 성공적으로 제공되어 충분하지 않으므로 .catch(next)에 포함되지 않았습니다.

sendMail 기능을 수정하는 해결책을 원하지 않습니다. 이 같은 버그가 있으면 그냥 기록하고 싶습니다.

어쨌든 .catch()sendMail에 넣지 않고 이러한 유형의 오류를 포착하고 기록 할 수 있습니까?

답변