java.lang.Object
info.ejava.examples.common.web.BaseExceptionAdvice
info.ejava.examples.db.validation.contacts.controller.ExceptionAdvice

@RestControllerAdvice public class ExceptionAdvice extends BaseExceptionAdvice
  • Constructor Details

    • ExceptionAdvice

      public ExceptionAdvice()
  • Method Details

    • handle

      @ExceptionHandler(jakarta.validation.ConstraintViolationException.class) public org.springframework.http.ResponseEntity<MessageDTO> handle(jakarta.validation.ConstraintViolationException ex)
      Spring will throw a ConstraintViolationException when failing validation for non-@RequestBody paramters or vanilla non-HTTP AOP calls.
    • handle

      @ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public org.springframework.http.ResponseEntity<MessageDTO> handle(org.springframework.web.bind.MethodArgumentNotValidException ex)
      This exception is thrown when an HTTP/Controller method fails validation during for @RequestBody parameters. This custom exception handler changes the response from a terse 400/BAD_REQUEST to a 422/UNPROCESSABLE_ENTITY with a descriptive error message.
      Parameters:
      ex - exception thrown by Web tier
      Returns:
      response entity with error message