Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Execution of failed with error: Javascript runtime exceeded limit of 200ms

We have an OPDK Apigee 18.01 installation. Couple of our policies keep experiencing an intermittent issue of

`Javascript runtime exceeded limit of 200ms`

Below is the sample of one of our proxies

<!-- Sets the 'accessToken.isJwt' variable for later use in validating the token --> 
<Javascript async="false" continueOnError="false" enabled="true" timeLimit="200" name="Javascript.IsJwt"> 
      <DisplayName>Javascript.IsJwt</DisplayName> 
      <ResourceURL>jsc://Javascript.IsJwt.js</ResourceURL> 
</Javascript>

Our `timeLimit` is set for 200ms, below is the javascript code for the policy. Are they suggestion or feedback what could be causing the errors.

var accessToken = context.getVariable('request.header.Authorization');
// Expecting a string with 3 fields separated by 2 dot characters if it is a
// JWT token.
var isJwt = accessToken !== null && characterCount(accessToken, '.') === 2;
context.setVariable("accessToken.isJwt", isJwt);
function characterCount(str, character) {
  var count = 0;
  for (var i = 0; i < str.length; i++) {
    if (str[i] === character) {
      count++;
    }
  }
  return count;
}
0 1 1,394
1 REPLY 1