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));
}
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));
}
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));
}
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")));
}
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);
}
Aggregations