Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle ETIMEDOUT error?

Tags:

How to handle etimedout error on this call ?

 var remotePath = "myremoteurltocopy"  var localStream = fs.createWriteStream("myfil");;         var out = request({ uri: remotePath });         out.on('response', function (resp) {             if (resp.statusCode === 200) {                 out.pipe(localStream);                 localStream.on('close', function () {                     copyconcurenceacces--;                     console.log('aftercopy');                     callback(null, localFile);                 });             }             else                 callback(new Error("No file found at given url."), null);         }) 

There are a way to wait for longer? or to request the remote file again?

What exactly can cause this error? Timeout only?

like image 657
mcbjam Avatar asked May 13 '14 13:05

mcbjam


People also ask

How do you handle error connecting Etimedout?

In the handler you can check if the error is ETIMEDOUT and apply your own logic: if (err. message. code === 'ETIMEDOUT') { /* apply logic */ } . If you want to request for the file again, I suggest using node-retry or node-backoff modules.

What causes Etimedout error?

The ETIMEDOUT error means that the request took more time than the webserver configuration allows and the connection has been closed by the server.

What does Esockettimedout mean?

ESOCKETTIMEDOUT means network timeout, you know that is a common problem when dealing with request/response so you should have handled the error in callback by yourself. All reactions.


1 Answers

This is caused when your request response is not received in given time(by timeout request module option).

Basically to catch that error first, you need to register a handler on error, so the unhandled error won't be thrown anymore: out.on('error', function (err) { /* handle errors here */ }). Some more explanation here.

In the handler you can check if the error is ETIMEDOUT and apply your own logic: if (err.message.code === 'ETIMEDOUT') { /* apply logic */ }.

If you want to request for the file again, I suggest using node-retry or node-backoff modules. It makes things much simpler.

If you want to wait longer, you can set timeout option of request yourself. You can set it to 0 for no timeout.

like image 170
Farid Nouri Neshat Avatar answered Oct 29 '22 15:10

Farid Nouri Neshat