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.