ControllerAdvice for Invalid Enums in request parameter

Viewed 28

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.

1 Answers

You need to handle IllegalArgumentException!

please refer this post

Related