【问题标题】:catch http.call timeout exception捕捉 http.call 超时异常
【发布时间】:2016-08-02 23:49:44
【问题描述】:

此 Meteor 服务器代码使用 http@1.2.8,在慢速互联网连接期间,它会在终端上打印以下内容:

response = HTTP.call(method, url, {
  timeout: 30000,
  headers: header,
  content: content,
  followRedirects: true
});

异步函数回调异常:错误:ETIMEDOUT 在 Object.Future.wait (/abc/xyz/.meteor/packages/meteor-tool/.1.4.0.i9pn2o++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64 /dev_bundle/server-lib/node_modules/fibers/future.js:449:15)

如何优雅地捕获此错误以便通知客户?谢谢

【问题讨论】:

    标签: meteor


    【解决方案1】:

    只需使用 try catch

    try{
        response = HTTP.call(method, url, {
            timeout: 30000,
            headers: header,
            content: content,
            followRedirects: true
        });
    }
    catch(e){
        if(e.code==="ETIMDOUT"){
            //alert the client
        }
    }
    

    【讨论】:

    • 当我向客户端抛出错误时,错误看起来是否仍然与服务器端相同?
    猜你喜欢
    • 2015-07-07
    • 1970-01-01
    • 2012-01-10
    • 2020-04-20
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多