How to extract the "reason" part of JSON Threat Protection's fault string?

I'm trying to customize the JTP policy's error response. Specifically, I'd like to go from the default response...

{
  "fault": {
    "faultstring": "JSONThreatProtection[JPT-SecureRequest]: Execution failed. reason: JSONThreatProtection[JTP-SecureRequest]: Exceeded object entry name length at line 2",
    "detail": {
      "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
    }
  }
}

... to something like this...

{
  "errorMessage": "JSON Threat Protection: Exceeded object entry name length at line 2"
}

I can't figure out how to directly access the "Exceeded object entry name length at line 2" part of the faultstring. Seems like there should be some variable or property exposing this but I'm coming up blank.

Is there a better way to achieve this than using JavaScript to manipulate the faultstring?

Thanks!

Solved Solved
0 3 280
1 ACCEPTED SOLUTION

I think there is no variable that holds *just* the reason. But , wow, it sure seems like it would be nice if there WAS a variable to hold that. I'll file a change request and we'll make that happen. (Edit: reference b/145832956)

For now I think you have to resort to the string parsing as you described.

Sorry.

View solution in original post

3 REPLIES 3

I think there is no variable that holds *just* the reason. But , wow, it sure seems like it would be nice if there WAS a variable to hold that. I'll file a change request and we'll make that happen. (Edit: reference b/145832956)

For now I think you have to resort to the string parsing as you described.

Sorry.

Thanks! This would be a great feature for customizing error responses.

Side note: While trying different solutions I found a strange behavior, possibly a bug. When formatting the string in the AssignMessage policy using the template's "replaceAll" method, the function fails whenever the regex contained a colon. For example, the function call below returns an empty string.

<Payload contentType="application/json">
{
    "errorMessage": "JSON Threat Protection: {replaceAll("hello: world", ":", ',')}"
}
</Payload>

// Payload becomes "JSON Threat Protection: "

As far as I know, this is valid Java Regex and should work.

yes, probably. . . There's a way to avoid the problem you encountered. Store the regex itself into a variable, using an AssignMessage policy.

<AssignMessage name='AM-Variabkles'>
  <AssignVariable>
    <Name>regex1</Name>
    <Value>hello: world</Value>
  </AssignVariable>
</AssignMessage>

And then

<Payload contentType="application/json">{
  "errorMessage": "JSON Threat Protection: {replaceAll(regex1,':',',')}"
}
</Payload>

Please ensure

  • no spaces between the arguments to replaceAll
  • quoted strings use single quotes