I have a server URL like this;
http://127.0.0.1:8888/stk?list=XXX,YYY
The server URL is tested to be working. I have a restify client that makes a HTTP GET to this URL and if things are working, a json output will be returned.
This is how the restify client code looks like;
var restify = require('restify');
var client = restify.createClient({
url: 'http://127.0.0.1:8888'
});
client.get('/stk?list=XXX,YYY', function(err, req) {
assert.ifError(err); // connection error
req.on('result', function(err, res) {
assert.ifError(err); // HTTP status code >= 400
res.body = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
res.body += chunk;
});
res.on('end', function() {
console.log(res.body);
});
});
});
The error was at assert.ifError(err);
because err
was null.
What is wrong with the code?