1

Controller:

@GetMapping  
public Page<...> list(Pageable pageable, Filter filter){  
    ...  
}

Filter class:

@Data  
@Builder  
public class Filer{  
    private String name;  
    private Type type;  // Enum
}

Working API calls:

/page=0&size=20   
/page=0&size=20&type=one  
/page=0&size=20&type=two 

Notworking API call:

/page=0&size=20&type=invalidEnum 

The above API call returns no output. Meaning the response in postman is empty. If an exception is thrown, then I will be able to handle using controlleradvice... But with no output returned can anyone guide me on how I can handle it with controlleradvice.

Nagulan S
  • 617
  • 5
  • 11

1 Answers1

2

You need to handle IllegalArgumentException!

please refer this post

지인호
  • 31
  • 3
  • For that we need to have a converter class ryt? My doubt is can we just handle it with annotations in controller class and handling the exception in controlleradvice. – Nagulan S Aug 29 '22 at 05:12
  • You don't need to convert that exception to custom exception! Just handle it like this... @ExceptionHandler(IllegalArgumentException.clss) – 지인호 Aug 29 '22 at 05:19
  • @ExceptionHandler(IllegalArgumentException.class) public ResponseEntity handleIllegalArgumentException(IllegalArgumentException e) { return new ResponseEntity<>("I messed up enum IllegalArgumentException", HttpStatus.INTERNAL_SERVER_ERROR); } tried this.. Exception is not getting caught – Nagulan S Aug 29 '22 at 05:33