I have set timelimit 1 sec in JS policy
timeLimit="1000"
continueOnError="true" //also checked with false
When a JavaScript file takes too long to execute, I encounter a timeout error in Postman, and the subsequent policies do not execute. I've included a try-catch block in the API call within the JavaScript file, but it's not triggering as expected. I want to ensure that all policies run even if the JavaScript policy times out. I also tried using RaiseFault to handle this situation, but it isn’t working. Additionally, I need to set those errors in a variable so I can use them in subsequent policies based on certain conditions. I am working on Apigee Edge. FaultRules is also not working.
JS policy:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="true" continueOnError="true" enabled="true" timeLimit="1000" name="JS-AuthHandler">
<DisplayName>JS-AuthHandler</DisplayName>
<Properties/>
<ResourceURL>jsc://AuthHandler.js</ResourceURL>
</Javascript>
Error:
{
"fault": {
"faultstring": "Execution of JS-AuthHandler failed with error: Javascript runtime exceeded limit of 1000ms",
"detail": {
"errorcode": "steps.javascript.ScriptExecutionFailed"
}
}
}
For capturing the 'api.timeout.error' , we tried FaultRule even it is not going inside it because next policy/line not executing due timeout error.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Javascript async="true" continueOnError="true" enabled="true" timeLimit="1000" name="JS-AuthHandler">
<DisplayName>JS-AuthHandler</DisplayName>
<FaultRules>
<FaultRule name="JavaScript Policy Faults">
<Step>
<Name>RF-HandleJsError</Name>
<Condition>(fault.name Matches "ScriptExecutionFailed") </Condition>
</Step>
<!--<Condition>(javascript.JavaScript-1.failed = true) </Condition>-->
</FaultRule>
</FaultRules>
<Properties/>
<ResourceURL>jsc://AuthHandler.js</ResourceURL>
</Javascript>
Even tried to keep FaultRule code in PreFLow also, but not working.
In short whenever any error is coming in JS policy then it is terminating the pipeline on JS policy only, not executing the remaining steps/policies. But here, we want to handle this timeout error, so we can retry auth call again.