How to identify error if it is raised by backend

Hi All,

In my target fault rules, i have a javascript where I want to identify error source type. For example, I can receive 503/502 which can be caused in below scenarios,

1. APIGEE tried to connect to backend and got the errors.

2. Backend sent 503/502 to apigee in response.

Now I want to differentiate the above scenarios, Is there any apigee reference variable I can use for this purpose.

Thanks,

Krish

0 4 2,057
4 REPLIES 4

Hi @Krish

You can use response.status.code variable in the response flow in your policy and do the needful.

NOTE: Make sure you include 5xx in the success.codes in the TargetEndpoint properties. For more info, search for success.codes here

Hey @Krish,

You can differentiate between backend errors and faults by using fault.name.

By default your TargetEndpoint treats 4xx and 5xx as errors, so when any of those are received from your backend, the target enters the target fault flow and sets:

fault.name = ErrorResponseCode

and it doesn't override the response with a fault representation, which is good because you'll want to process the error response.

If its a fault raised by Edge, like when the target server is down (e.g. 503), Edge sets:

fault.name = NoActiveTargets

or some other value depending on the fault.

You can still check for other things like the error.status.code in the target fault flow, but now you have a way of differentiating 503.

This should be documented in the custom target error code handling section (update request submitted). The error code reference does not explicitly address target response errors, but the Service Callout policy errors does reference it.

NOTE: Service Callouts do not set fault.name = ErrorResponseCode as that page states, just ExecutionFailed (update request submitted).

Useful information. Thank you @Kurt Kanaskie

I just tested 504 and the fault.name coming as "GatewayTimeout". My question is, instead of handling the different fault name is there any reference variable I can use which indicates that the error occurred while apigee tried to connect to the backend, no matter 502, 503, 503, etc.

<Condition>fault.name != "ErrorResponseCode"</Condition>

will let you know the 4xx or 5xx was a fault from Edge and not the backend.