Closed subnetmarco closed 3 years ago
Also the default 404
message when an API is not found could be customized.
This would make sense, I'm just starting to use Kong and really surprised to not see this functionality at all!
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.
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.
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).
(Possibly) traced the problem to the lua module, asking there: https://github.com/openresty/lua-nginx-module/issues/875
@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.
@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.
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.
Hi, any news about this? If not, anyone would be able to point out a fork with some progress about it? Cheers.
@tetebueno there is a hack that we did. Overriding the kong.tools.response file.
Hi @mwaaas , we are after this feature too, can you please tell us how you changed kong.tools.response?
Hi, anyone got a working sample for achieving this, customising the error message? appreciate any help thanks
@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.
Is this implemented yet ?
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.