Hi ,
I am working on exception handling at policy level sample.I have created a proxy with no endpoint.
I have called a backend service which throws HTTP Status code 404.I have attached a RaiseFaultPolicy to the proxy endpoint.When backend call got failed ,it has to call RaiseFaultPolicy based on condition written.But I am getting a generic error .Could you please help on this .I wanted to display the error message prepared in RaiseFaultPolicy.
Here are details.
Proxy : exceptionhandling-policyleve
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> /exceptionhandling-policylevel 1480511423220 nvraghavendra254@gmail.com ExceptionHandling-PolicyLevel 1480666142732 nvraghavendra254@gmail.com Service-Callout-1 Service_callout_Error default false
Proxy endpoint:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Service_callout_Error (Response.status.code = 404)or(calloutResponse.message.content Like "*Resource not found*") Service-Callout-1 /exceptionhandling-policylevel default
Service callout policy calls backend(Service-Callout-1):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Service Callout-1 false calloutResponse http://www.thomas-bayer.com/sqlrest/CUSTOMER/44444444444444
RaiseFaultPolicy(Service_callout_Error):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Service_callout_Error 500 Server Error true
Response I am getting :
{"fault":{"faultstring":"Execution of ServiceCallout Service-Callout-1 failed. Reason: ResponseCode 404 is treated as error","detail":{"errorcode":"steps.servicecallout.ExecutionFailed"}}}
Hi @veeraraghavendra
Please find the code below:
- Service Callout policy: I have included a property - success.codes with 4xx as well so that Edge treats it as a success and proceeds with the flow. More about this and other properties here
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout-1">
<DisplayName>Service Callout-1</DisplayName>
<Properties/>
<Request clearPayload="true" variable="myRequest">
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</Request>
<Response>calloutResponse</Response>
<HTTPTargetConnection>
<URL>http://www.thomas-bayer.com/sqlrest/CUSTOMER/44444444444444</URL>
<Properties>
<Property name="success.codes">1xx,2xx,3xx,4xx</Property>
</Properties>
</HTTPTargetConnection>
</ServiceCallout>
-
No change to your Raise Fault policy
-
In your proxy endpoint, put a condition
<Request>
<Step>
<Name>Service-Callout-1</Name>
</Step>
<Step>
<Name>Service_callout_Error</Name>
<Condition>(calloutResponse.status.code == 404)</Condition>
</Step>
</Request>
Would recommend this as you can have customized error message for different status codes and also for different service callouts (if you have many) within the same proxy.
Try this out and let me know if this worked
@Sai Saran Vaidyanathan: I sai saran ,I have created a new proxy ,but I am getting error ‘com.apigee.kernel.exceptions.spi.UncheckedException’.Here are details .
Proxy .xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> /exceptionhandlingatservicecalloutpolicy 1480924708504 nvraghavendra254@gmail.com ExceptionHandlingatServicecallOutpolicy 1480925619945 nvraghavendra254@gmail.com Raise-Fault-1 Service-Callout-1 default default false
Proxy endpoint:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> (calloutResponse.status.code == 404)or(calloutResponse.message.content Like "*Resource not found*") Service-Callout-1 Raise-Fault-1 (calloutResponse.status.code == 404) /exceptionhandlingatservicecalloutpolicy default default
Target endpoint:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> https://testurl.com
Service callout :Service-Callout-1
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Service Callout-1 false calloutResponse http://www.thomas-bayer.com/sqlrest/CUSTOMER/44444444444444 1xx,2xx,3xx,4xx
Raise fault policy:Service_callout_Error
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> Service_callout_Error 500 Server Error true
Everything goes fine till raise fault policy ,even condition also met . But it is trhowing error .
Do we need to create a fault rule at the proxy level to handle the excpetion raised in policy or RaiseFaultpolicy at the policy level will be able to handle .please suggest me on this.
Hi @veeraraghavendra - Please remove the Fault Rules from the proxy end point. You don’t need that as you have a Raise Fault policy already for that condition.
Let me know if that fixed the issue
NOTE: Please use the CODE formatter when pasting any code in the editor (the option with CODE in the editor) so that its more readable
Hi @Sai Saran Vaidyanathan,I have removed the fault rules ,But still getting error ’
| com.apigee.kernel.exceptions.spi.UncheckedException’ |
Please correct me ,if I did any thing wrong.
Hi @veeraraghavendra - Can you attach the bundle here ?
Hi @veeraraghavendra - I imported the bundle you attached and it works as expected. I didnt have to do any change. Are you using Cloud version or the OnPrem (private cloud) version ? If Private Cloud, which version are you on ?
Hi @Sai Saran Vaidyanathan ,I am using 'Private Cloud releases 4.16.01’ .
I am using APIGEE private cloud.
@arghya das - something that can be checked ? The proxy bundle is attached above and the issue is coming on 4.16.01