Quarkus hibernate validations exceptions not showing on the console

Viewed 1016

I have a simple project using Quarkus 1.4.2. When I use the @Valid annotation, and the validations fail with a status 500, the exception is not show on the console. Only in the Swagger UI. What should I do to print it out on the console?

@ApplicationScoped
public class ProductService {
    public void validateProduct(@Valid Product product) {

    }
}

The exception that is occurring is:

javax.validation.UnexpectedTypeException: HV000030: No validator could be found for constraint

The error is correct. It is just not shown on the console.

2 Answers

I would expect the error to be logged as it's definitely a usability issue. And I would expect it to be logged on startup when we collect the Hibernate Validator metadata, not for every call.

You could create a reproducer and open a GitHub issue in the Quarkus tracker here.

I'll check it out and see if something needs fixing.

If I understand correctly, you need to use the Validator object in order to catch possible Exceptions:

@Inject
Validator validator;

public void validateProduct(Product product) {
    // Should throw an error
    Set<ConstraintViolation<Product>> violations = validator.validate(product);
    if(violations.isEmpty()) {
        return;
    }
    for (ConstraintViolation<Product> violation : violations) { // or log whole set as json
        System.out.println(violation.toString()); //TODO prettify
    }
    throw new ValidationException(JsonbBuilder.create().toJson(violations));
}

If you get a 500 error, you can now catch it and log.

Or just catch UnexpectedTypeException where you call your service. This might be better.

Related