2013-04-09 2 views
0

얘들 아 내가 커피 스크립트에 HTTP 요청을 처리하기 위해 노력하고 있지만, 앱에서 바로 아래에 오류가 죽으면 아래 경우에 서버가, 내가 올바른 솔루션을커피 스크립트

코드를 찾을 수 없습니다에 HTTP를 erorrs 처리 :

http.get "http://localhost:8080/health", (res) -> 
     status = res.statusCode 
     value = if status == 200 then 1 else 0 
     console.log value 
     server.push_metric metricPrefix , value 
     res.on 'error',() -> 
      colsone.log "Tomcat Disconected" 

오류 :

events.js:71 
     throw arguments[1]; // Unhandled 'error' event 
        ^
Error: connect ECONNREFUSED 
    at errnoException (net.js:770:11) 
    at Object.afterConnect [as oncomplete] (net.js:761:19) 

답변

1

난 당신이 적극적으로 별도의 이벤트 처리기에서 오류를 수신 할 생각합니다. 지금 당장 당신은 이벤트 핸들러를 응답 (res)에 붙이고 있지만 요청 객체 자체에 첨부해야합니다. the docs을 참조하십시오. 또한

req = http.get "http://localhost:8080/health", (res) -> 
    status = res.statusCode 
    value = if status == 200 then 1 else 0 
    console.log value 
    server.push_metric metricPrefix , value 

req.on 'error', -> 
    console.log "Tomcat Disconected" 

, 당신은 당신의 현재의 에러 핸들러에 오타가 있습니다 colsone.log