Api MGT return http 500 instead of 401,403

Wanexa 0 Reputation points
2024-07-23T16:28:47.34+00:00

Hello

So I tried to figured out how to retrieve error code from my azure function instead of http 500 from the api mgt.

On the function app side when one of the header is missing or invalid value 401,403 is returned with a message.

But when I called the the same route from my api mgt it gave me http 500 .

As far as I rode I'm not supposed to add some return-response , am I right / wrong or should I have to add smth like that ?

<return-response> <set-status code="401" reason="Unauthorized"/> <set-header name="test" exists-action="override"> <value>Bearer error="invalid_token"</value> </set-header> </return-response>

If someone can help me please

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,951 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,661 questions
{count} votes

Accepted answer
  1. JananiRamesh-MSFT 23,651 Reputation points
    2024-07-24T12:40:07.81+00:00

    @Wanexa Thanks for reaching out. APIM acts as a reverse proxy for your backend APIs. When a client sends a request to an API that is exposed through APIM, APIM forwards the request to the backend API and returns the response from the backend API to the client.

    From the description i understand that when you call your function app directly with a missing header you receive 401/403 response code but returns an HTTP 500 error code when called via APIM with a missing header. This could be due to an issue with the configuration of your APIM instance or a policy that is causing the issue.

    More details on the 500 errors where the response did not come from backend can be found in the OCP-APIM trace please refer: https://learn.microsoft.com/en-us/azure/api-management/api-management-howto-api-inspector#trace-a-call-in-the-portal

    The trace can provide more information about what is causing the HTTP 500 error code to be returned and can help you identify the issue.

    do try and let me know incase of further issues, I would be happy to assist you.


0 additional answers

Sort by: Most helpful