use of jakarta.validation.ConstraintDeclarationException in project resteasy by resteasy.
the class ResteasyViolationExceptionMapper method toResponse.
public Response toResponse(ValidationException exception) {
if (exception instanceof ConstraintDefinitionException) {
return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
if (exception instanceof ConstraintDeclarationException) {
return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
if (exception instanceof GroupDefinitionException) {
return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
if (exception instanceof ResteasyViolationException) {
ResteasyViolationException resteasyViolationException = ResteasyViolationException.class.cast(exception);
Exception e = resteasyViolationException.getException();
if (e != null) {
return buildResponse(unwrapException(e), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
} else if (resteasyViolationException.getReturnValueViolations().size() == 0) {
return buildViolationReportResponse(resteasyViolationException, Status.BAD_REQUEST);
} else {
return buildViolationReportResponse(resteasyViolationException, Status.INTERNAL_SERVER_ERROR);
}
}
return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
use of jakarta.validation.ConstraintDeclarationException in project hibernate-validator by hibernate.
the class MostSpecificValueExtractorTest method parallelValueExtractorDefinitionsCausesException.
@Test
@TestForIssue(jiraKey = "HV-1306")
public void parallelValueExtractorDefinitionsCausesException() throws Exception {
Validator validator = Validation.byProvider(HibernateValidator.class).configure().addValueExtractor(new IWrapper21ValueExtractor()).addValueExtractor(new IWrapper211ValueExtractor()).addValueExtractor(new IWrapper212ValueExtractor()).addValueExtractor(new IWrapper22ValueExtractor()).addValueExtractor(new IWrapper221ValueExtractor()).buildValidatorFactory().getValidator();
try {
validator.validate(new Entity2(null));
fail("An exception should have been thrown");
} catch (ConstraintDeclarationException e) {
String message = e.getMessage();
assertThat(message).startsWith("HV000219");
assertThat(message).contains(Wrapper2.class.getName());
assertThat(message).contains(IWrapper21ValueExtractor.class.getName());
assertThat(message).doesNotContain(IWrapper211ValueExtractor.class.getName());
assertThat(message).doesNotContain(IWrapper212ValueExtractor.class.getName());
assertThat(message).contains(IWrapper22ValueExtractor.class.getName());
assertThat(message).doesNotContain(IWrapper221ValueExtractor.class.getName());
}
}
Aggregations