API를 사용하여 타사 웹 사이트에서 뉴스 피드를 가져 오는 코드가 있습니다. 5 초마다 실행되도록 설정하고 발생할 수있는 모든 뉴스 트랜잭션을 가져옵니다. 문제는 새로운 트랜잭션이 발생하지 않는 것 같습니다.http.get 응답에서 캐치되지 않는 예외를 처리하는 방법
process.on ('uncaught 예외', function (error) {console.log ("hmph"}})을 추가하면 cron 작업이 5 초 후에 계속 될 수 있으므로, 이다; 그러나, 나는 console.log ("hmph")를 추가했고 지금은 혼란 스럽다.
처음으로 콘솔은 hmph를 작성합니다. 5 초 후에 그것은 쓸 것이다 hmph hmph
등등. 내가 뭔가를 놓치고 있어야한다는 것을 알고 있지만, 나는 그것이 무엇인지는 확실히 모른다. 나는 request.end()를하기 위해 else 문에서 시도했지만 에러는 여전히 발생한다. process.on없이
('캐치되지 않는 ...') 발생 오류는 다음 proccess.on와events.js:71 throw arguments[1]; // Unhandled 'error' event ^ Error: Parse Error at Socket.socketOnData (http.js:1367:20) at TCP.onread (net.js:403:27)
('캐치되지 않는 ...')를을 console.log (오류)입니다 :
{ [Error: Parse Error] bytesParsed: 161, code: 'HPE_INVALID_CONSTANT' }
이 오류를 올바르게 처리하려면 어떻게해야합니까?
단축 코드 : 첫 번째 요청을 보낼 때
이var job = new cronJob('*/5 * * * * *', function(){
var request = http.get({
host: 'www.example.com',
path: '/news_feed?apicode=myapicode',
port: 80,
headers: { 'accept-encoding': 'gzip' }
})
request.on('response', function(response){
if (response.statusCode == 200){
// gunzip response, save response to mongodb
}
else
{
// here is where the error is occuring
process.on('uncaughtException',function(error){
console.log(error);
console.log("hmph");
}
});
}, null, true);
답변 해 주셔서 감사합니다. 그러나, 나는 이미 그것을 시도하고 얻을 : events.js : 71 던져 인수 [1]; // 처리되지 않은 '오류'이벤트 ^ 오류 : 구문 분석 오류 (Socket.socketOnData (http.js : 1367 : 20) , TCP.onread (net.js : 403 : 27) – thtsigma
) 내가 말한 같은 장소에서? 당신은 uncaughtException 핸들러를 가지고있는 것처럼 응답 콜백 내에 에러를 넣지 않는다. – loganfsmyth
그래, 나는 그 자리에서 체크했다. 제안 된 전체 코드가 있습니다. http://pastebin.com/PTu7cA8s – thtsigma