Skip to content

Commit

Permalink
Remap some JsonMappingExceptions to 408 and 400
Browse files Browse the repository at this point in the history
  • Loading branch information
eager-signal committed Apr 15, 2024
1 parent 9cad2c6 commit 1df824d
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@
import com.fasterxml.jackson.databind.JsonMappingException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import java.util.concurrent.TimeoutException;

public class JsonMappingExceptionMapper implements ExceptionMapper<JsonMappingException> {
@Override
public Response toResponse(final JsonMappingException exception) {
if (exception.getCause() instanceof TimeoutException) {
return Response.status(Response.Status.REQUEST_TIMEOUT).build();
}
if ("Early EOF".equals(exception.getMessage())) {
// Some sort of timeout or broken connection
return Response.status(Response.Status.BAD_REQUEST).build();
}
return Response.status(422).build();
}
}

0 comments on commit 1df824d

Please sign in to comment.