I use an API with notable timeout to response and I always faced Error: socket hang up
on request
module in nodejs
it's happened although I could CURL url without any problem. I tried to increase the timeout
in request options but nothing good happened. Is there something else instead of timeout? Should I use other packages instead of request
?
the nodejs
code:
var request = require("request");
var options = {
method: 'GET',
url: 'https://someapiurl.com/api/search',
qs: { q: 'Vanak sq' },
timeout: 12000,
time: true
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
the error:
Error: Error: socket hang up
at Request._callback (/home/mohammad/Desktop/test.js:14:20)
at self.callback (/home/mohammad/node_modules/request/request.js:188:22)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.onRequestError (/home/mohammad/node_modules/request/request.js:884:8)
at emitOne (events.js:101:20)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketOnEnd (_http_client.js:345:9)
at emitNone (events.js:91:20)
at TLSSocket.emit (events.js:185:7)
via MDK
No comments:
Post a Comment