javascript - Node http.ClientRequest does not fire "error" event -
i have following javascript node.js code:
var options = { host: "x.y.z" ,path: "/api/abc/" ,method: "get" }; var req = http.request(options); req.on('response' , function(data) { console.log("response: ",data.statuscode); done(); }); req.on('error' , function() { console.log("error"); done(); }); req.end();
i can't error
event when actual http request error occurs. missing ?
preliminary findings: appear failure case "no response server" (e.g. due network issue) not fire event. so, workaround create 'timer' , trap condition yourself.
try using if / else statement instead of 2 independent functions.
if(response want && response.statuscode = 200){ //logic } else { //console.log("error") }
Comments
Post a Comment