Return 5xx HTTP status for invalid target types with Jackson
InvalidDefinitionException has been introduced in Jackson 2.9 to be able to differentiate invalid data sent from the client (should still generate a 4xx HTTP status code) from server side errors like beans with no default constructor (should generate a 5xx HTTP status code). Issue: SPR-14925
This commit is contained in:
@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.ConversionNotSupportedException;
|
||||
import org.springframework.beans.TypeMismatchException;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.HttpMessageNotReadableException;
|
||||
import org.springframework.http.converter.HttpMessageNotWritableException;
|
||||
@@ -354,7 +355,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to read HTTP message: " + ex);
|
||||
}
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
response.sendError(ex.getErrorStatus().orElse(HttpStatus.BAD_REQUEST).value());
|
||||
return new ModelAndView();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user