use of org.graylog2.plugin.rest.ApiError in project graylog2-server by Graylog2.
the class JacksonPropertyExceptionMapper method toResponse.
@Override
public Response toResponse(PropertyBindingException e) {
final Collection<Object> knownPropertyIds = firstNonNull(e.getKnownPropertyIds(), Collections.emptyList());
final ApiError apiError = new ApiError("Unable to map property " + e.getPropertyName() + ".\nKnown properties include: " + Joiner.on(", ").join(knownPropertyIds));
return status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity(apiError).build();
}
use of org.graylog2.plugin.rest.ApiError in project graylog2-server by Graylog2.
the class JsonProcessingExceptionMapperTest method testToResponse.
@Test
public void testToResponse() throws Exception {
final ExceptionMapper<JsonProcessingException> mapper = new JsonProcessingExceptionMapper();
final JsonParser jsonParser = new JsonFactory().createParser("");
final JsonMappingException exception = new JsonMappingException(jsonParser, "Boom!", new RuntimeException("rootCause"));
final Response response = mapper.toResponse(exception);
assertEquals(response.getStatusInfo(), Response.Status.BAD_REQUEST);
assertEquals(response.getMediaType(), MediaType.APPLICATION_JSON_TYPE);
assertTrue(response.hasEntity());
assertTrue(response.getEntity() instanceof ApiError);
final ApiError responseEntity = (ApiError) response.getEntity();
assertTrue(responseEntity.getMessage().startsWith("Boom!"));
}
Aggregations