Is there an attribute in fault object to get the error message?

I am trying to get the error message for fault in policy execution. For eg: Quotaviolation

I am aware of fault.name and fault.string. Fault.string provides all the details including the policy name etc. Is there a way to just get the error message?

Solved Solved
0 3 910
1 ACCEPTED SOLUTION

@Nagashree B , What do you mean by just error message ? Can you explain please ?

Yes, Fault string does contain error message. For example,

{"fault": {

    "faultstring":"Rate limit quota violation. Quota limit  exceeded. Identifier : _default",

    "detail": {"errorcode":"policies.ratelimit.QuotaViolation"}

   }

}

You can extract message from fault string using Extract Variables policy. If you need a detailed message to be given to application or end user please use Assign Message Policy in fault rules to change the response.

Check attached proxy that demonstrates same.

Cheers,

Anil Sagar

View solution in original post

3 REPLIES 3

@Nagashree B , What do you mean by just error message ? Can you explain please ?

Yes, Fault string does contain error message. For example,

{"fault": {

    "faultstring":"Rate limit quota violation. Quota limit  exceeded. Identifier : _default",

    "detail": {"errorcode":"policies.ratelimit.QuotaViolation"}

   }

}

You can extract message from fault string using Extract Variables policy. If you need a detailed message to be given to application or end user please use Assign Message Policy in fault rules to change the response.

Check attached proxy that demonstrates same.

Cheers,

Anil Sagar

Is there a way to escape special characters in faultstring data, I am getting a faultstring like below with '\' appended to every double quotes within the fault string however when I do the extract variable like in your example the new variable does not escape double quotes.

eg

{ "fault": {

"faultstring": "Execution of prepare_data failed on line 15 with error: access denied (\"java.net.NetPermission\" \"specifyStreamHandler\")",

"detail": { "errorcode": "steps.javascript.ScriptExecutionFailedLineNumber" }

}

}

Extract variable:

<Source>error</Source>

<JSONPayload>

<Variable name="errorMessage" type="string"> <JSONPath>$.fault.faultstring</JSONPath>

</Variable>

</JSONPayload>

errorMessage is set to :

Execution of prepare_data failed on line 15 with error: access denied ("java.net.NetPermission" "specifyStreamHandler"

I am trying to use errorMessage variable inside json payload like below, which is causing double quotes inside double quotes and failing

<Set> <Payload contentType="application/json" variablePrefix="@" variableSuffix="#">

{ "code": "@flow.error.code#",

"message": "@errorMessage#",

"errorType":"@flow.error.reason#" }

</Payload>

<StatusCode>{flow.error.status}</StatusCode>

<ReasonPhrase>{flow.error.reason}</ReasonPhrase>

</Set>

Appreciate your response!

Hi - sorry we never responded to this. You can wrap the policy with an escapeJSON to do the right thing in the payload. like this:

<Set>
  <Payload contentType="application/json">{
  "code": "{escapeJSON(flow.error.code)}",
  "message": "{escapeJSON(errorMessage)}",
  "errorType":"{escapeJSON(flow.error.reason)}"
}</Payload>
  <StatusCode>{flow.error.status}</StatusCode>
  <ReasonPhrase>{flow.error.reason}</ReasonPhrase>
</Set>