How to handle ETIMEDOUT error?

后端 未结 3 490
感情败类
感情败类 2020-12-05 05:26

How to handle etimedout error on this call ?

 var remotePath = \"myremoteurltocopy\"
 var localStream = fs.createWriteStream(\"myfil\");;
        var out = r         


        
相关标签:
3条回答
  • 2020-12-05 05:36

    In case if you are using node js, then this could be the possible solution

    const express = require("express");
    const app = express();
    const server = app.listen(8080);
    server.keepAliveTimeout = 61 * 1000;
    

    https://medium.com/hk01-tech/running-eks-in-production-for-2-years-the-kubernetes-journey-at-hk01-68130e603d76

    0 讨论(0)
  • 2020-12-05 05:39

    We could look at error object for a property code that mentions the possible system error and in cases of ETIMEDOUT where a network call fails, act accordingly.

    if (err.code === 'ETIMEDOUT') {
        console.log('My dish error: ', util.inspect(err, { showHidden: true, depth: 2 }));
    }
    
    0 讨论(0)
  • 2020-12-05 05:42

    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.

    0 讨论(0)
提交回复
热议问题