Is it possible to transform Gateway Error Response Status Codes?

Given that Tyk Gateway responses include HTTP status codes that follow the HTTP status code standard as stated in this docs. Is it possible to transform the standard Gateway Error Response Status Code to another HTTP Status Code?

So far I’ve only found that you can customize the messages through error templating, but not the HTTP Status Code and also some limited override messages configuration property in the Gateway.

As an example,
Let’s say that there’s something wrong with policy in the JWT token. The gateway will return 403 - Key not authorised: no matching policy error from Tyk Gateway. But in my case, I need it to return 401 HTTP status code instead.

Hi Nicotanzil,

Welcome to the community :raised_hand:

Tyk supports error templating to customize error message bodies for specific HTTP status codes, However it does not allow changing the actual HTTP status codes returned by built-in Gateway errors.

The only way to control both the status code and message is to use a custom authentication middleware and override messages as highlighted in Troubleshooting and Debugging. We support limited customisation of the error codes and messages returned by custom authentication middleware
Your custom middleware sends an error with a status code and message, Tyk Gateway reads your API definition’s override_messages section and checks if there is a matching override for that status code or error key, If it finds a match for that status code or error, it replaces the status code and/or message with your custom values before sending the response to the client.

Hope this helps.

Regards