0

Is there any way to get inside to the exception object when using annotation @ExceptionHandler?

this is my code:

@ExceptionHandler(DataInputException.class)
    public ResponseEntity handleException(){
         return ResponseEntity
                    .status(HttpStatus.BAD_REQUEST)
                    .body("Entity contains null or forbidden values");
    }

I'd like to have returned message to contain customized info about perticular fields. (That's why I need error object).

476rick
  • 2,764
  • 4
  • 29
  • 49
filemonczyk
  • 1,613
  • 5
  • 26
  • 47

1 Answers1

3

Pass in the exception

@ExceptionHandler(DataInputException.class)
public ResponseEntity handleException(DataInputException exception) {
Reimeus
  • 158,255
  • 15
  • 216
  • 276