use of io.dropwizard.jersey.errors.ErrorMessage in project dropwizard by dropwizard.
the class BooleanParamTest method booleanParamNegativeTest.
private void booleanParamNegativeTest(@Nullable String input) {
final ErrorMessage expected = new ErrorMessage(400, "Parameter must be \"true\" or \"false\".");
assertThatExceptionOfType(WebApplicationException.class).isThrownBy(() -> new BooleanParam(input)).satisfies(e -> assertThat(e.getResponse().getStatus()).isEqualTo(400)).satisfies(e -> assertThat(e.getResponse().getEntity()).isEqualTo(expected));
}
use of io.dropwizard.jersey.errors.ErrorMessage in project dropwizard by dropwizard.
the class AbstractParam method error.
/**
* Given a string representation which was unable to be parsed and the exception thrown, produce
* a {@link Response} to be sent to the client.
*
* By default, generates a {@code 400 Bad Request} with a plain text entity generated by
* {@link #errorMessage(Exception)}.
*
* @param input the raw input value
* @param e the exception thrown while parsing {@code input}
* @return the {@link Response} to be sent to the client
*/
protected Response error(@Nullable String input, Exception e) {
LOGGER.debug("Invalid input received: {}", input);
String errorMessage = errorMessage(e);
if (errorMessage.contains("%s")) {
errorMessage = String.format(errorMessage, parameterName);
}
return Response.status(getErrorStatus()).entity(new ErrorMessage(getErrorStatus().getStatusCode(), errorMessage)).type(mediaType()).build();
}
Aggregations