How can I get error messages set in HTTP responses created from BadRequestException? #36243
-
I'm just starting out with Quarkus, and trying a simple resource: @Path("/")
public class FooResource {
@Produces(MediaType.APPLICATION_JSON)
@GET
@Path("/items")
public List<Integer> items(@RestQuery final String filter) {
if (filter == null) {
throw new BadRequestException("missing 'filter' parameter");
}
return Collections.emptyList();
}
} If I test this locally using curl, I get the correct 400 status code, but no message body: $ curl -i localhost:80/items
HTTP/1.1 400 Bad Request
content-length: 0
Is there some I need to change to get the Exception's message set as part of the response body? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
/cc @cescoffier (adr) |
Beta Was this translation helpful? Give feedback.
-
CC @geoand |
Beta Was this translation helpful? Give feedback.
-
The fastest way is to add |
Beta Was this translation helpful? Give feedback.
Thanks, that also works. I was mostly wondering about the general approach though, in my application I'm passing one of the parameters to another service, so don't know whether it's an invalid parameter until part way through the method execution.
I solved it in the end by creating a mapper for the exception instead: