Informative Error From Gateway if execution of one of Policy like ServiceCallOut fails

We have API proxy attached which has many policies like AuthenticateUser which is a Service Callout Policy which hits the service.

So we have below cases of errors from Gateway

1. Where actual service is down, in this case Gateway throws below error

Http Status Code 500

{
    "fault": {
        "faultstring": "Execution of ServiceCallout AuthenticateUser failed. Reason: ResponseCode 500 is treated as error",
        "detail": {
            "errorcode": "steps.servicecallout.ExecutionFailed"
        }
    }
} 

2. Below is the URL used in Service Call out

<URL>http://test.internal.com:8080/openam/json/{realm}/authenticate</URL>

So now suppose {realm} which is coming from query parameter tenantId, if that is not present, below error comes from Gateway

Http Status Code 500

{
    "fault": {
        "faultstring": "Unresolved variable : realm",
        "detail": {
            "errorcode": "messaging.runtime.UnresolvedVariable"
        }
    }
} 

It looks like errors from the gateway need to be more informative and put in the context of the caller.

The existing message is very obscure. This is both an API usability and supportability issue.

So now we want customize error messages to be user friendly if any Policy like Service CallOut above fails so that Message should help in understanding the issue.

Thanks

legacy-api-v1-document-rev1-2016-08-24.zip

1 1 196
1 REPLY 1

You can handle the service callout failure with a fault rule, structured like this:

<FaultRule name="service-callout-error">
    <Condition>(fault.name = "ExecutionFailed")</Condition>
    <Step>
      <Name>AM-SC-Execution-Failed</Name>
    </Step>
</FaultRule>

You can avoid the "UnresolvedVariable" error by employing a condition on a RaiseFault step prior to the ServiceCallout, like this:

    <Flow name='flow 1'>
      <Request>
        <Step>
          <Name>RF-MissingParameter</Name>
          <Condition>request.queryparam.tenantId = null</Condition>
        </Step>
        <Step>
          <Name>SC-Call-External-Service</Name>
        </Step>
        ...

In the above:

  • AM-SC-Execution-Failed is an AssignMessage policy that sets the response message you want
  • RF-MissingParameter is a RaiseFault policy that returns what you want
  • SC-Call-External-Service is the ServiceCallout policy