Search in sources :

Example 6 with ErrorMessage

use of org.molgenis.web.ErrorMessageResponse.ErrorMessage in project molgenis by molgenis.

the class RestController method handleMethodArgumentNotValidException.

@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(BAD_REQUEST)
public ErrorMessageResponse handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
    LOG.debug("", e);
    List<ErrorMessage> messages = Lists.newArrayList();
    for (ObjectError error : e.getBindingResult().getAllErrors()) {
        messages.add(new ErrorMessage(error.getDefaultMessage()));
    }
    return new ErrorMessageResponse(messages);
}
Also used : ObjectError(org.springframework.validation.ObjectError) ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) ErrorMessageResponse(org.molgenis.web.ErrorMessageResponse)

Example 7 with ErrorMessage

use of org.molgenis.web.ErrorMessageResponse.ErrorMessage in project molgenis by molgenis.

the class ErrorMessageResponseTest method ErrorMessageResponseListErrorMessage.

@Test
public void ErrorMessageResponseListErrorMessage() {
    List<ErrorMessage> errorMessages = Arrays.asList(new ErrorMessage("message1"), new ErrorMessage("message2"));
    ErrorMessageResponse errorMessageResponse = new ErrorMessageResponse(errorMessages);
    assertEquals(errorMessageResponse.getErrors(), errorMessages);
}
Also used : ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) Test(org.testng.annotations.Test)

Aggregations

ErrorMessage (org.molgenis.web.ErrorMessageResponse.ErrorMessage)7 Test (org.testng.annotations.Test)4 ErrorMessageResponse (org.molgenis.web.ErrorMessageResponse)3 ConstraintViolation (org.molgenis.data.validation.ConstraintViolation)1 ObjectError (org.springframework.validation.ObjectError)1