Pass-through Callout error response to calling client

Not applicable

Hi,

I want to pass-through the callout error content (including body and headers and status code) to the client.

I set the *continueOnError=false* in the callout policy, but an unhandled fault is triggered that overrides the response with a generic internal error.

I tried using a FaultRule on ExecutionFailed to copy the body, but I can't access the callout response headers or the status code.

I have several callouts in my proxy so creating a handler/extractor for each seems redundant code.

Can you please advice?

Thanks in advance.

0 3 426
3 REPLIES 3

Hi @Julio Rincon

I don't understand this: "I can't access the callout response headers or the status code."

Why not?

I suppose the ServiceCallout stores the response in a response object.

This object will be available in the message context. Why can you not reference "scResponse.header.whatever" ?

Not sure about the "multiple callouts" and redundant code. If it is getting messy you may wish to consider nodejs to script it.

adas
New Member

@Julio Rincon Try referring to this post: https://community.apigee.com/questions/15051/how-to-set-cookies-received-in-response-of-service.html

It gives you the handle to the service callout response object including headers. In the simplest of cases, you would do something like this:

            <Step>
                <Name>AuthAPIServiceCallout</Name>
            </Step>
            <Step>
                <Condition>(AuthAPIResponse.status.code!=200)</Condition>
                <Name>RaiseFaultAuthAPI</Name>
            </Step>

In the raise fault policy you could access the service callout response headers (or pre-parse it using javascript) and return appropriate errors.

Not applicable

Hello @Julio Rincon,

Have you tried accessing "ServiceCallout.response" or "servicecallout.{policy-name}.failed" to detect the error and raise your custom fault ?