0

I have a Get request: \allTopic
It inputs a filterCriteria custom object which contains multiple fields and one of those is an Enum called Role, which is either student or teacher

And there are many more different API calls with different Enums. So I want to create @controllerAdvice that can handle all these.

I need help with

  1. Annotations to put in the Get API controller function header
  2. Annotations to put in the filterCriteria class
  3. What particular exception to handle in @exceptionHandler in @controlleradvice
Nagulan S
  • 617
  • 5
  • 11

1 Answers1

0

I have some similar code as per your need, please have a look


@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler(value = PageNotFoundException.class)
    public String pageNotFoundException(PageNotFoundException exception){
        return "error/404";
    }

    @ExceptionHandler(value = AuthFailedException.class)
    public String authFailedException(AuthFailedException exception){
        return "error/401";
    }

    @ExceptionHandler(value = ServerException.class)
    public String serverException(ServerException exception){
        return "error/500";
    }
}

Afterwards, you can throw any of the given type of exception.
please note, you have to create such your exception.

Example:

public class PageNotFoundException extends RuntimeException{

}


I hope, it helps!
Shyam Patel
  • 381
  • 2
  • 13