Class GlobalValidExceptionHandler

java.lang.Object
com.app.controller.exceptionsHandler.GlobalValidExceptionHandler

@RestControllerAdvice public class GlobalValidExceptionHandler extends Object
Global exception handler for validation-related exceptions. Handles ValidationException and IllegalArgumentException by returning a 400 BAD REQUEST status with the exception message. Catches all other exceptions to return a 500 INTERNAL SERVER ERROR status.
  • Constructor Details

    • GlobalValidExceptionHandler

      public GlobalValidExceptionHandler()
  • Method Details

    • illegalArgumentException

      @ExceptionHandler({ValidationException.class,IllegalArgumentException.class}) @ResponseStatus(BAD_REQUEST) public ResponseDto<String> illegalArgumentException(Exception e)
      Handles validation and illegal argument exceptions. Returns HTTP 400 BAD REQUEST with the exception message.
      Parameters:
      e - the validation or illegal argument exception
      Returns:
      response containing the exception message
    • exception

      @ExceptionHandler(Exception.class) @ResponseStatus(INTERNAL_SERVER_ERROR) public ResponseDto<String> exception(Exception e)
      Handles any other uncaught exceptions. Returns HTTP 500 INTERNAL SERVER ERROR with a generic error message.
      Parameters:
      e - the general exception
      Returns:
      response indicating an internal server error occurred