Find your content:

Search form

You are here

Read timeout error calling a third party REST API

 
Share

I am getting Read timeout error while calling a third party REST API.

Can I catch it using try catch block? Or it is not catchable like other Limit Exceptions. Please explain.


Attribution to: doga

Possible Suggestion/Solution #1

Yes, you can catch the CalloutException; from the Apex Web Services and Callouts wiki article:

try {
    //Execute web service call here     
    HTTPResponse res = http.send(req);  

    //Helpful debug messages
    System.debug(res.toString());
    System.debug('STATUS:'+res.getStatus());
    System.debug('STATUS_CODE:'+res.getStatusCode());       
} catch(System.CalloutException e) {
    //Exception handling goes here.... retry the call, whatever
}

As logontokartik mentions in the comment above, you can also set the timeout on the callout:

req.setTimeout(60000); // timeout in milliseconds - this is one minute

The default timeout is 10 seconds. The minimum is 1 millisecond and the maximum is 120 seconds.


Attribution to: metadaddy
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1715

My Block Status

My Block Content