ServiceCallout : how to exploit the response

Not applicable

Hi,

I'm using "servicecallout" so that I can call an external endpoint.

The problem is that that endpoint can return 401 (I can see it on that remote web service).

I would like to create a new step with a policy that could execute the following algorithm but I don't know how to do :

if (ServiceCallout.response.status == 401)    
	stopEverythingAndReturnError();
else    
	continue();

Is it possible ?

Regards

0 3 1,274
3 REPLIES 3

hi @pasteur, this article explaining how to handle custom error code with service call out policy might help you - https://github.com/apigee/api-platform-samples/tree/master/learn-edge/service-callout-2

Hi @pasteur -

Make sure ServiceCallout.response.status is the response variable defined in your Service Callout policy. For example, here's the default Service Callout configuration:

...
    <Response>calloutResponse</Response>
...

Give this, you'd use calloutResponse.response.status.

This is also described in the docs.

Hope this helps.

Not applicable

You can also use Fault rules for errors in the call out and handle it as an error...

http://docs.apigee.com/api-services/reference/service-callout-policy#errors


<FaultRulename="RequestVariableNotMessageType">
<Step>
<Name>AM-RequestVariableNotMessageType</Name></Step><Condition>(fault.name = "RequestVariableNotMessageType")</Condition></FaultRule>