javascript - Node.js application quits if other server is unreachable. How do I prevent my application from stopping? -
I am writing an application that regularly checks for a newer version of the software to check with a remote server Is this node My first attempt at JS, please stand with me. When the server is up and running, the program runs perfectly fine.
However, when the server is not running, the program ends with an error:
events.js: 72 throw er; // Unchecked 'error' event ^ Error: Inonu FUSD Connect on Object Exception (Net JS: 904: 11) [Incomplete form] (NET JS: 895: 19)
What I have read, I believe I have set up my code to handle errors by including a response.on ('error', ...) in part of my callback. However, as you can see from the error, it is not giving me the console.logs the error, which I tried to set up. Here's a part of my code that is not working, if I can include other parts when needed, then this is a very large application at this point:
var index = Require ("./index"); Var http = Required ('http'); Var FS = Requirement ("FS"); "Local version": "4.2.1", "hostVersion": "", "downloadURL": ""}] / checks the host server for the host version, hostnfo as the JSN object function check ) {Callback1 = function} {var str = ''; var hostObject; Response.on ('data', function (chuck) {str = = chuck;}); Response.on ('error', function (err) } {Console.log ('problem with request:' + err.message); hostObject = "why, error?" + Err.message}); app [0] ["hostVersion"] = host object [0] [ "Version"]; app [0] [a] applications [1] ["downloadURL"] = host object [1] ["download"] = [1] ["Download URL"]; [1] ["hostVersion"] = Host Object [1] ["version" DownloadURL "] console.log (app [0] [" hostVersion "] +": received IDSocket host version "); index.everyFourHours (); }}}} Http.request (hostinfo, callback1) .end ();};
Thanks in advance with any help, thanks in advance!
EDIT: Whatever I have tried:
Try to block both the http.request line as well as the entire callback function with the catch blocks, which is just console.log Error
process.on ('uncaughtException'
domain.c Reate & amp; domain .run
You receive an error handler with your http.request
.
For example, you can call your http.request
:
var req = http.request (hostinfo, Callback1); Req.on ('error', function (err) {console.log ("error:" + err.message);}); req.end ();
Read more for more information.
Comments
Post a Comment