How to avoid the timeout error while executing httpSend within javaScript Policy?

plvndinesh
Participant II

While calling external url from javascrit policy, I am facing error when resp time exceeds 200ms if res is less than 200ms it is working fine.

Method build:

if any error in this method please state.

function postCall(url,header,body) {
  var req = new Request(url, 'POST', header, JSON.stringify(body));
  var exchange = httpClient.send(req); exchange.waitForComplete();
  if (exchange.isSuccess()) {
    var responseObj = exchange.getResponse().content.asJSON;
    if (responseObj.error){
      throw new Error(responseObj.error_description); 
    }
    //Returning the response of the respective url;
    exchange.getResponse();
  } 
  else if (exchange.isError()) {
    throw new Error(exchange.getError()); 
  }
}
0 1 456
1 REPLY 1

You are running into the time limit on the JavaScript policy.

See the documentation for an explanation.

The workaround is to design your JS to run more quickly.