Why is Azure API Management hides response body for status codes 4** and 5**

Mariusz Klimek 21 Reputation points

I created an API in Azure API Management and I realized that APIM actually hides some of the bodies I return.

I get 200, but I don't get 404, 401 and 500.

I understand that it's better to control what is returned and that we don't want to give the end-user HTML with 500 error body.

I use 404 or 401 in my API along with returning messages to the user. Is there a possibility to control what is being returned for certain status codes?

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

2 answers

Sort by: Most helpful
  1. Mike Urnun 5,501 Reputation points

    Hi @Mariusz Klimek

    You'll need to add an on-error policy and use it in conjunction with the set-body policy to ensure the response body coming from your API is carried over to the response that the caller receives. In order to implement it, please review the following:

  2. Dan Cundy 1 Reputation point

    Hi @Mike Urnun

    After following the documentation at the error management page below and adding the error policy sample into the <on-error> section


    I'm still getting my 401 Reponses masked with a 500. Does that sounds like correct behaviour?