APIM <on-error> policy and <outbound> policy

chadwell 0 Reputation points
2024-04-16T10:24:21.0333333+00:00

I am using an APIM to passthrough to a backend service and I wanted to implement better logging and observability for errors when things go wrong either in the APIM itself, or at the backend.

I introduced an <on-error> block which has a <trace> which uses the Last.ErrorMessage etc. This then goes automatically to logs and application insights. It worked well for 500 errors in the APIM - I can see the trace in the logs with the error messages etc

However, I noticed that 400 - Bad request errors from the backend did not get logged in the trace. I believe this was due to the: "fail-on-error-status-code" not being set in the forward-request policy. When I set this to true then it caught the 400 errors on the <on-error> policy and added a trace to those.

All good so far. Except that the <outbound> policy has a few emit-metrics, log-to-eventhub, and retry logic which no longer seem to be triggered.

If the backend triggers an error and it now goes into the <on-error> block (because fail-on-error-status-code is now true) - is the <outbound> policy completely ignored and nothing in it will be executed?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,768 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Aki Nishikawa 635 Reputation points Microsoft Employee
    2024-04-25T06:52:52.02+00:00

    Yes, unable to go back to outbound section once entering on-error section.

    0 comments No comments