0

Dear Quarkus community,

I'm having a quick question: how to set / specify / what-to-implement in Quarkus to get a JSON based response for generic 404 cases? By default, an HTML based response is returned. For an API only service, that may not be acceptable.

This question addresses only the cases when a call is done to a non existent paths such as http://localhost:8080/some-wrong-path.

Note: I'm not asking about to implement a ExceptionMapper<WebApplicationException> or ContainerResponseFilter. The wrong path/route cases are handled before these application provided implementations.

Thanks!


Expectations

Instead of getting an HTML based response like this:

<html>

<head>
    <title>Error</title>
</head>

<body>Not Found</body>

</html>

I'd like to respond with in a JSON format, something like this:

{
  "error": "Whatever error"
  "details": "Potentially further details"
}
dxps
  • 78
  • 7
  • https://marcelkliemannel.com/articles/2021/centralized-error-handling-and-a-custom-error-page-in-quarkus/ – Luca Basso Ricci May 23 '23 at 10:15
  • Thanks for the feedback, but I already tested all those options presented in the article. Those works as long as the request gets into your app, aka a known path is used. It seems that in the case I described there is a need for a lower (probably Undertow) level related implementation. – dxps May 23 '23 at 10:39
  • 1
    Update: Hmm... started playing with the code, and it seems that the first example (global-error-response-filter) returns a JSON! Nice!!! I will play a little bit more and come back here with the final result. – dxps May 23 '23 at 10:48

0 Answers0