Fred J.
Fred J.

Reputation: 6049

catch http.call timeout exception

This Meteor server code uses [email protected], during slow internet connection it prints the below to the terminal:

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

Exception in callback of async function: Error: ETIMEDOUT at 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)

How do I gracefully catch this error so that I can inform the client? Thanks

Upvotes: 0

Views: 1086

Answers (1)

Michael Balmes
Michael Balmes

Reputation: 334

Just use a 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
    }
}

Upvotes: 1

Related Questions