Print this page

HTTPResponse status code returned on an apex callout timeout?

Knowledge Article Number 000212634
Description What is returned in the HTTPResponse when the Salesforce timeout limit is reached when performing a callout to an external system? 
Resolution If a callout timeout is reached there will be no HTTPResponse created, instead a CalloutException will be thrown.

You can catch and handle a CalloutException as follows:

 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....
 }

You can also increase the HTTPRequest timeout to a maximum of 120 seconds as follows:

HttpRequest req = new HttpRequest();
req.setTimeout(2000); // timeout in milliseconds, up to 120000




promote demote