Request validation with quarkus

671 Views Asked by At

I have a REST Enspoint

... @GET public Response read (@Valid Param parameters) {

} ...

How can I catch this Exception to handle this in Quarkus? Is there a special Exceptionhandler available?

1

There are 1 best solutions below

2
geoand On

You can handle the exception by using:

@Provider
public class MyViolationExceptionMapper implements ExceptionMapper<ValidationException> {

    @Override
    public Response toResponse(ValidationException exception) {
        // do something
    }

}

You can draw inspiration for how to handle things by looking at the built-in exception mapper.