Skip to content

Commit

Permalink
[RESTEASY-3443] In the JsonProcessingExceptionMapper currently return…
Browse files Browse the repository at this point in the history
…s a 500 status. However, it's more correct to return a 400 as it's a processing error. This is not backwards compatible. It can easily be overridden by creating a custom ExceptionMapper.

https://issues.redhat.com/browse/RESTEASY-3443
Signed-off-by: James R. Perkins <jperkins@redhat.com>
  • Loading branch information
jamezp committed Feb 2, 2024
1 parent 08ade56 commit 73446c4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ public class JsonProcessingExceptionMapper implements ExceptionMapper<JsonProces
@Override
public Response toResponse(final JsonProcessingException exception) {
JacksonLogger.LOGGER.logCannotDeserialize(exception);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(JacksonLogger.LOGGER.cannotDeserialize()).build();
return Response.status(Response.Status.BAD_REQUEST).entity(JacksonLogger.LOGGER.cannotDeserialize()).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testAircraftFailure() throws Exception {
String response = sendPost(new TestPolymorphicType(new Aircraft()));
logger.info("response: " + response);
Assert.assertNotNull(response);
Assert.assertTrue(response.contains("Response code: " + HttpResponseCodes.SC_INTERNAL_SERVER_ERROR));
Assert.assertTrue(response.contains("Response code: " + HttpResponseCodes.SC_BAD_REQUEST));
Assert.assertTrue("Expected response to contain \"Not able to deserialize data provided\" but was \"" + response + "\"",
response.contains("Not able to deserialize data provided"));
}
Expand All @@ -101,7 +101,7 @@ public void testAutomobileFailure() throws Exception {
String response = sendPost(new TestPolymorphicType(new Automobile()));
logger.info("response: " + response);
Assert.assertNotNull(response);
Assert.assertTrue(response.contains("Response code: " + HttpResponseCodes.SC_INTERNAL_SERVER_ERROR));
Assert.assertTrue(response.contains("Response code: " + HttpResponseCodes.SC_BAD_REQUEST));
Assert.assertTrue("Expected response to contain \"Not able to deserialize data provided\" but was \"" + response + "\"",
response.contains("Not able to deserialize data provided"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public void testBad() throws Exception {
String response = sendPost(new TestPolymorphicType(new Aircraft()));
logger.info("response: " + response);
Assert.assertNotNull(response);
Assert.assertTrue(response.contains("Response code: " + HttpResponseCodes.SC_INTERNAL_SERVER_ERROR));
Assert.assertTrue(response.contains("Response code: " + HttpResponseCodes.SC_BAD_REQUEST));
Assert.assertTrue("Expected response to contain \"Not able to deserialize data provided\" but was \"" + response + "\"",
response.contains("Not able to deserialize data provided"));
}
Expand Down

0 comments on commit 73446c4

Please sign in to comment.