0

I created a JsonClient with node.js restify.

var json_client = restify.createJsonClient({
    url: 'http://127.0.0.1:8888',
    version: '~1.0'
});

json_client.get('/test?list=' + test_list, function (err, req, res, test_list_results) {
            if (err) {
                console.log('err: ' + err);
            }
            else
            {
                console.log('success');
            }
}

I deliberately turn off the webserver to see if an error was captured. No error was captured. The code inside json_client.get was skipped. How can some form of error be detected?

EDIT: I discovered something while experimenting after getting answer from Quentin. If I leave out connectTimeout, an error message does appear. Just need to wait for seconds later.

guagay_wk
  • 26,337
  • 54
  • 186
  • 295

1 Answers1

1

Add connectTimeout: someNumber to your options. (Or possibly just wait long enough).

Having done that, I get:

%  node tet.js
err: Error: connect ECONNREFUSED 127.0.0.1:8888
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • 1
    With all the other options like url and version. – Quentin Nov 10 '15 at 00:07
  • I looked at https://www.npmjs.com/package/restify-clients It advises `The default is not to set a connectTimeout, so you end up with the node.js socket defaults.` Is that sound advice? Without connectTimeout, I get no error msg. – guagay_wk Nov 10 '15 at 00:09
  • I check http://restify.com/#jsonclient It doesn't say the time unit in `connectTimeout: someNumber`. Is `someNumber` in ms or seconds? – guagay_wk Nov 10 '15 at 00:13
  • I discovered something. If I leave out `connectTimeout`, an error message does appear. Just need to wait for seconds later. – guagay_wk Nov 10 '15 at 00:18