Get which variable failed in ExtractVariable Policy

If an ExtractVariable policy, if we are trying to get something from a JSON that doesn't exist, we get a general error such as

{"fault":{"faultstring":"Invalid JSON path $.cardToken in policy EV-GetClientParams.","detail":{"errorcode":"steps.extractvariables.InvalidJSONPath"}}}

Can we specifically get which of the variables we failed to retrieve?

Solved Solved
0 5 210
1 ACCEPTED SOLUTION

@Ghassan Barghouti - I dont think the policy checks all the variables and then gives the list of missing attributes. It processes each variable and raise the fault in the first instant. Its the developer's responsibility to handle that by using Conditions and RaiseFault policies. If you dont want the policy to fail, then just set <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>. For more info, check this doc

View solution in original post

5 REPLIES 5

@Ghassan Barghouti - I dont think the policy checks all the variables and then gives the list of missing attributes. It processes each variable and raise the fault in the first instant. Its the developer's responsibility to handle that by using Conditions and RaiseFault policies. If you dont want the policy to fail, then just set <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>. For more info, check this doc

Ok cool. But when it raises the fault, is there a way to know on which variable it raised the fault?

I was able to get the faultstring using a JavaScript policy within the FaultRules

<FaultRules>
        <FaultRule name="print-EV-error">
            <Step>
                <Name>JS-print-error</Name>
            </Step>
            <Condition>extractvariables.EV-GetClientParams.failed = true</Condition>
        </FaultRule>
    </FaultRules><br>

and in the JS-print-error policy, I had the following JS code

var faultStr = error.content.asJSON.fault.faultstring;
print(faultStr); //Invalid JSON path $.cardToken in policy EV-GetClientParams.
var varStr = faultStr.split("Invalid JSON path ")[1].split(" ")[0];
print(varStr); //$.cardToken

That printed the faultstring and the variable within that string. You can fetch it in other ways as well. This was a quick one I wrote just now

Oh thanks. I didn't even notice there was a $.cardToken inside the string 😕

Haha - so I gave you more than what you want 🙂