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

Mariusz Klimek 21 Reputation points
2020-05-21T21:48:32.05+00:00

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,740 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Mike Urnun 9,646 Reputation points Microsoft Employee
    2020-05-23T19:24:50.157+00:00

    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
    2021-08-09T09:56:25.6+00:00

    Hi @Mike Urnun

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

    api-management-error-handling-policies

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

    0 comments No comments