Search in sources :

Example 1 with ErrorMessage

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

the class RestController method handleAuthenticationException.

@ExceptionHandler(AuthenticationException.class)
@ResponseStatus(UNAUTHORIZED)
public ErrorMessageResponse handleAuthenticationException(AuthenticationException e) {
    LOG.info("", e);
    // workaround for https://github.com/molgenis/molgenis/issues/4441
    String message = e.getMessage();
    String messagePrefix = "org.springframework.security.core.userdetails.UsernameNotFoundException: ";
    if (message.startsWith(messagePrefix)) {
        message = message.substring(messagePrefix.length());
    }
    return new ErrorMessageResponse(new ErrorMessage(message));
}
Also used : ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) ErrorMessageResponse(org.molgenis.web.ErrorMessageResponse)

Example 2 with ErrorMessage

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

the class ErrorMessageResponseTest method addErrorMessages.

@Test
public void addErrorMessages() {
    ErrorMessage errorMessage1 = new ErrorMessage("message1");
    ErrorMessage errorMessage2 = new ErrorMessage("message2");
    List<ErrorMessage> errorMessages1 = Arrays.asList(errorMessage1, errorMessage2);
    ErrorMessage errorMessage3 = new ErrorMessage("message3");
    ErrorMessage errorMessage4 = new ErrorMessage("message4");
    List<ErrorMessage> errorMessages2 = Arrays.asList(errorMessage3, errorMessage4);
    ErrorMessageResponse errorMessageResponse = new ErrorMessageResponse();
    errorMessageResponse.addErrorMessages(errorMessages1);
    errorMessageResponse.addErrorMessages(errorMessages2);
    assertEquals(errorMessageResponse.getErrors(), Arrays.asList(errorMessage1, errorMessage2, errorMessage3, errorMessage4));
}
Also used : ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) Test(org.testng.annotations.Test)

Example 3 with ErrorMessage

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

the class ErrorMessageResponseTest method ErrorMessageResponseErrorMessage.

@Test
public void ErrorMessageResponseErrorMessage() {
    ErrorMessage errorMessage = new ErrorMessage("message");
    ErrorMessageResponse errorMessageResponse = new ErrorMessageResponse(errorMessage);
    assertEquals(errorMessageResponse.getErrors(), Collections.singletonList(errorMessage));
}
Also used : ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) Test(org.testng.annotations.Test)

Example 4 with ErrorMessage

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

the class ErrorMessageResponseTest method addErrorMessage.

@Test
public void addErrorMessage() {
    ErrorMessageResponse errorMessageResponse = new ErrorMessageResponse();
    ErrorMessage errorMessage1 = new ErrorMessage("message1");
    ErrorMessage errorMessage2 = new ErrorMessage("message2");
    errorMessageResponse.addErrorMessage(errorMessage1);
    errorMessageResponse.addErrorMessage(errorMessage2);
    assertEquals(errorMessageResponse.getErrors(), Arrays.asList(new ErrorMessage("message1"), new ErrorMessage("message2")));
}
Also used : ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) Test(org.testng.annotations.Test)

Example 5 with ErrorMessage

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

the class RestController method handleMolgenisValidationException.

@ExceptionHandler(MolgenisValidationException.class)
@ResponseStatus(BAD_REQUEST)
public ErrorMessageResponse handleMolgenisValidationException(MolgenisValidationException e) {
    LOG.info("", e);
    List<ErrorMessage> messages = Lists.newArrayList();
    for (ConstraintViolation violation : e.getViolations()) {
        messages.add(new ErrorMessage(violation.getMessage()));
    }
    return new ErrorMessageResponse(messages);
}
Also used : ConstraintViolation(org.molgenis.data.validation.ConstraintViolation) ErrorMessage(org.molgenis.web.ErrorMessageResponse.ErrorMessage) ErrorMessageResponse(org.molgenis.web.ErrorMessageResponse)

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