@ControllerAdvice
public final class ControllerExceptionHandler {
// More code
@ExceptionHandler(IllegalArgumentException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public final ErrorResponse processIllegalArgument(final IllegalArgumentException ex) {
LOGGER.debug("Intercepted IllegalArgumentException");
return new DefaultErrorResponse(resolveLocalizedErrorMessage(ex.getMessage()));
}
// More Code
}
The @ExceptionHandler defines the exception to capture, and @ResponseStatus the status for the response.
@ControllerAdvice
public class DefaultErrorHandler extends ResponseEntityExceptionHandler