I am trying to handle a http request in coffeescript, but in case the server is down the app just dies with error below, and I can't find the right solution.
Code:
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"
error:
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)