Fault handling for Response 503

Not applicable

We are trying to simulate negative scenario for Response code 503 which needs to be handled with custom fault handling, but we are getting apigee fault handling message like below.

{"fault":{"faultstring":"The Service is temporarily unavailable","detail":{"errorcode":"messaging.adaptors.http.flow.ServiceUnavailable"}}}

Attached the sample bundle.

Please let us know where we are missing?

0 8 7,788
8 REPLIES 8

By default, Edge treats HTTP response codes in the 1xx-3xx range as 'success', and HTTP response codes in the range 4xx-5xx as 'failure'. That means any response from the backend service with an HTTP response code 4xx-5xx automatically invokes the Error flow, which then returns an error message directly to the requesting client.

In this case, target is unreachable and hence Apigee is returning 503 back to the client directly (not executing policies on the target pre/post flows). If you need to handle this fault, add your policies under FaultRules section. Checkout the "Custom handling of HTTP error codes from the target server" in this link Hope this helps!

can you please share me your contact number

Not applicable

Thanks Sudheendra. We have tried the same as per the link, but did not fire the custom fault policy. I have attached the bundle. Please let me know where I mistake?

780-faultrules.jpg

Please see the attached screenshot. Since you are using "http://weather.velapis.com" as the Target URL, Apigee is receiving Connection Refused Error. Hence Apigee is raising 503. Hence your FaultRules with condition with status code 502 or 503 are not triggered. I have also attached the updated API proxy here.

Not applicable

Thanks for quick response. In fiddler, I get response 502 for the target URL(attached), so I expect to get call "Return502" policy. However, could you please confirm whether we can use both fault handling in the target end point?

For reachable

<Response> <Step> <Name>Raise-Fault-1</Name> <Condition>(response.status.code = 404) or (response.status.code = 500)</Condition> </Step> </Response>

For unreachable

<FaultRules> <FaultRule name="target_not_reachable"> <Step> <Name>Return502</Name> </Step> </FaultRule> </FaultRules>

Not applicable

Hi Sudheendra, Attached bundle to get response 405 for the target URL, but still it calls unreachable policy(Return502). Could you please help to handle both reachable and unreachable target?

As I mentioned before policies under ProxyFlow and TargetFlow will not get executed when Error flow kicks-in. First you need to comment

<Properties><Property name="success.codes">404,405,502,503</Property></Properties>

Otherwise, Apigee considers all these status code as Success calls. Second I only see 502 RaiseFault in your Fault flow. Hence you only get 502 when there is an issue..

I have fixed your proxy and attached the updated one here. When you call

http://sudheendra-prod.apigee.net/humanaweatherapi/forecastrss

The target server returns "404 Not Found". We apply the RaiseFault policy and change the Status to 500. See the attached image.

789-sudheendra-apigee.jpg

Also faults are processed in a particular order. So it's really important to place the Faults in correct sequence to see them take effect.

As I mentioned before you need to have the policies under FaultRules section to be executed on an error/fault condition. Any policy under Proxy/Target flow will not be executed when it enters the error flow. In your proxy, I see that the required policies are either ProxyFlow or TargetFlow. You need to move them to FaultRules section. Also Fault Rules are executed in a sequence. Hence it's really important to focus on their placement as well.

I have fixed your proxy and attached here. In this case Target server returns a 404, however using policies we are changing that to 500 before sending back to the client.

793-sudheendra-apigee.jpg