Customize error messages for no route matches

Hello!

I want to modify or put some another message for routes that are not defined (aka the 404 Not Found pages in the websites, that we visit every day).

Would it be possible to return the same 404 HTML response instead of JSON response? Yes, it might break the clients, but that is what I require for now. If not, please suggest an alternative.

This is the message that I receive:

{
    "message": "no Route matched with those values"
}

I found an old issue for v0.12.x, but it is not applicable any more as that deals with former api entities.
Link: https://github.com/Kong/kong/issues/3192

Thanks!

Hi,

I think you could still use the solution from the issue you found but instead of attaching the plugin to api object, now you attach it to route object which might look like this {"protocols" : ["http", "https"]}, "paths" ; ["/"], "service" : {"id" : "<id of any existing service>"}}. The request-termination plugin does have config.body and config.content_type that might solve your problem

for my own clarity, looking to rephrase the question as a user story:

I want to change the HTML payload returned for a Route defined in the platform but continue to send HTTP 404 as the status code

If the above is true, you have multiple options. The request terminator plugin (as already noted) is totally viable.

If you want to present a different HTML payload, you could (could) get into some redirects that allow you to push all requests to a different service that has options for prettier, human friendly HTML pages.

I do think you should probably look at the application that’s calling APIs as the rendering layer and incorporate some basic mapping of the JSON payload being deterministic of the HTML payload within the app (if “not found”, show the “sad webpage”) and not try to make the JSON payload do something else. That’s just opinion and without knowing all the details of your requirements.