I have spring REST set up fine using Jackson/JSON and everything works.
But I knowingly introduced an error in the structure of the message which resulted in a 400 - Bad Request. But there was no log output on the server. The error I would be expecting would be something like "Jackson unknown property exception" or whatever but it was caught and a 400 error was sent to the client, but no log of the exception on the server.
I don't want to debug everything on the server clearly, but I want Spring network level exceptions like this clearly labelled as error.
What is the correct way to switch this on?
Thanks!
@ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public void handle(HttpMessageNotReadableException e) { logger.warn("Returning HTTP 400 Bad Request", e); }
Building on @Jukka's answer, you can enable this globally for all controllers using @ControllerAdvice
(introduced in Spring 3.2). It does require a little code on your end, but in my experience you usually end up needing a global error handling configuration anyways and this allows you to set breakpoints / easily inspect the problems.
An example of this is below:
@ControllerAdvice public class ControllerConfig { @ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public void handle(HttpMessageNotReadableException e) { log.warn("Returning HTTP 400 Bad Request", e); throw e; } }