Remap some JsonMappingExceptions to 408 and 400

This commit is contained in:
Chris Eager 2024-04-12 15:09:33 -05:00 committed by Chris Eager
parent 9cad2c6b7d
commit 1df824db7c
1 changed files with 8 additions and 0 deletions

View File

@ -3,10 +3,18 @@ package org.whispersystems.textsecuregcm.mappers;
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();
}
}