How to override response behavior and return a custom error message?

Not applicable

When there is a request e.g for an end point on non existing api proxy, edge returns HTTP 400 with a fault body having error code messaging.adaptors.http.configuration.ApplicationNotFound.

Is it possible to override this behavior and return 404 and a custom error message?

0 4 1,831
4 REPLIES 4

sgilson
Participant V

You can find an example in the doc here that shows how to do this. It actually shows an example of handling a 400 or a 500 response.

Stephen

Yes you can override the error message by writing fault rule to handle the error and then write raise fault or assign message step to handle it.

Not applicable

If there is a request for a non existing api proxy, then the error returned is 404 classification_failed. Incase you wish to override this with a custom error then deploy another catch-all proxy with basepath as '/' and set the custom payload there.

Not applicable

The only way to handle this would be to deploy another proxy with a basepath of "/" so that all requests atleast match that and then you can do customized error messages in that proxy using fault handling rules.

You can now define custom handlers for HTTP response codes 404 to return a customized response message to the requesting app.

The following TargetEndpoint uses the policy named ReturnError to handle HTTP 404

<TargetEndpoint name="default">
  <PreFlow name="PreFlow">
    <Request/>
    <Response>
      <Step>
        <Name>REf-policy</Name>
        <Condition>(response.status.code = 404) </Condition>
      </Step>
    </Response>
  </PreFlow>
</TargetEndpoint>


This TargetEndpoint configuration causes the policy called 
"REf-policy" to handle the response whenever the TargetEndpoint encounters an HTTP response code of 404.

Regards,
Madhumita