Kong / kong

🦍 The Cloud-Native API Gateway and AI Gateway.
https://konghq.com/install/#kong-community
Apache License 2.0
38.78k stars 4.77k forks source link

Being able to customize the upstream proxy errors #972

Closed subnetmarco closed 3 years ago

subnetmarco commented 8 years ago

Being able to customize the upstream error responses being returned by proxy_pass, by allowing to override the current templates.

The user would need to provide their own templates for all the response formats that we support.

subnetmarco commented 8 years ago

Also the default 404 message when an API is not found could be customized.

adamlc commented 8 years ago

This would make sense, I'm just starting to use Kong and really surprised to not see this functionality at all!

giorgiosironi commented 7 years ago

I was trying to work around this with:

        error_page 403 /4xx.html;
        location = /4xx.html {
            root /usr/local/openresty/nginx/html;
            internal;
        }

but it seems to have no effect.

giorgiosironi commented 7 years ago

The error I am trying to customize is the 403 coming from the key-auth plugin: https://github.com/Mashape/kong/blob/master/kong/plugins/key-auth/handler.lua#L80 However, after analysis I see there should be no difference between an upstream error and a ngx.exit() one, which is what this plugin is using through the responses module.

giorgiosironi commented 7 years ago

For anyone trying to do the same: I needed to add:

 proxy_intercept_errors on;

to the Nginx configuration for upstream errors to be passed to error_page directives.

Instead, 40x produced by a plugin (like key-auth) still are not intercepted (they're not coming from a proxy).

giorgiosironi commented 7 years ago

(Possibly) traced the problem to the lua module, asking there: https://github.com/openresty/lua-nginx-module/issues/875

arno-di-loreto commented 7 years ago

@thefosk Is there some news about this feature? I just started playing with Kong, it's really a great API gateway (kudos for everybody involved) but having these messages that do not comply to the format of the exposed API is really annoying, it breaks the API consistency.

subnetmarco commented 7 years ago

@arno-di-loreto we want to introduce this capability but currently we have other priorities. The only way today is to fork the plugins and change the message manually - but we want to provide an easier way.

mwaaas commented 7 years ago

Hey @thefosk @Tieske @thibaultcha I tried using Kong and its a really awesome project for api-gateway, For our case this feature is really important, would like to contribute to this feature, please guide me on how to do it.

tetebueno commented 6 years ago

Hi, any news about this? If not, anyone would be able to point out a fork with some progress about it? Cheers.

mwaaas commented 6 years ago

@tetebueno there is a hack that we did. Overriding the kong.tools.response file.

takearun commented 6 years ago

Hi @mwaaas , we are after this feature too, can you please tell us how you changed kong.tools.response?

srilathatata commented 6 years ago

Hi, anyone got a working sample for achieving this, customising the error message? appreciate any help thanks

mwaaas commented 6 years ago

@takearun created a folder called kong/tools and added response file to the directory, then added my directory to the lua path, in that way when Kong tries to import kong.tools.response it would import my file.

Let me know if that helps.

matti commented 6 years ago

https://github.com/Kong/kong/issues/3192

spmsupun commented 4 years ago

Is this implemented yet ?