Hi James,
Thanks for the reply. Sorry, there is a mistake in my example. In my particular case, I have an endpoint that takes a "status" enum:
localhost:8080/api/v1/users?status=creating
But when I use the wrong status, it will throw an exception:
java.lang.IllegalArgumentException: No enum constant com.data.model.UserStatus.creating
at java.base/java.lang.Enum.valueOf(Enum.java:273)
But the client will only receive a 404, with no error message.
What I was trying to say in the original email was, if number_param received something like a String:
localhost:8080/api/v1/users?number_param=asdf
Then
it will also return a 404 as a client error, due to this exception
Caused by: java.lang.NumberFormatException: For input string: "asdf"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
What I am trying to figure out, is, instead of an opaque 404, I would like to set it up to return helpful error messages to the client, such as:
- 'number_param' received 'asdf', expected a number/integer instead of a string
- 'status' received 'creating', valid values are ['created', 'pending', 'complete']
Thanks,
Arwin
Hello Arwin,
Sorry for the late reply. What kind of argument is "123"? What I mean is it a linked to an enum or special value of some sort?
As I understand it, a malformed @QueryParam will return a 404 with no message. For example, localhost:8080/api/v1/users?number_param=123 will respond with 404. Apparently, this is due to the JAX-RS spec:
```
3.2 Fields and Bean Properties
if the field or property is annotated with @MatrixParam, @QueryParam or @PathParam then an implementation MUST generate an instance of NotFoundException (404 status) that wraps the thrown exception and no entity
```
I would like the modify this behavior to:
1. Return a 400 status code, as I believe 404 causes confusion for users (they will think the endpoint doesn't exist)
2. Show a helpful error message, for example "'123' is an invalid input for number_param, expected number"
I have read that the way to do this is with the ExceptionMapper<E extends Throwable> interface. Is this true? And if so, which Exception E should I use? Is there something like a QueryParamException?
If it matters, I am using RESTEasy with Quarkus.
Thanks,
Arwin
_______________________________________________
resteasy mailing list --
resteasy@lists.jboss.org
To unsubscribe send an email to
resteasy-leave@lists.jboss.org
--
James R. Perkins
JBoss by Red Hat