Class APIExceptionHandler

java.lang.Object
com.nicholasalfonso.lato.security.APIExceptionHandler

@RestControllerAdvice public class APIExceptionHandler extends Object
Centralized exception handler that maps common API failures to JSON error responses.
  • Constructor Details

    • APIExceptionHandler

      public APIExceptionHandler()
  • Method Details

    • handleResponseStatusException

      @ExceptionHandler(org.springframework.web.server.ResponseStatusException.class) public org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorResponse> handleResponseStatusException(org.springframework.web.server.ResponseStatusException ex)
      Handles explicit HTTP status exceptions thrown by application services.
      Parameters:
      ex - the thrown status exception
      Returns:
      response entity with the corresponding HTTP status and error message
    • handleArgumentNotValidException

      @ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorDetailsResponse> handleArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException ex)
      Handles request body validation failures from Bean Validation annotations.
      Parameters:
      ex - the validation exception
      Returns:
      bad request response with field-level validation details
    • handleHttpRequestMethodNotSupportedException

      @ExceptionHandler(org.springframework.web.HttpRequestMethodNotSupportedException.class) public org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorResponse> handleHttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException ex)
      Handles unsupported HTTP method usage on a route.
      Parameters:
      ex - the method-not-supported exception
      Returns:
      method not allowed response with a descriptive message
    • handleMethodArgumentTypeMismatchException

      @ExceptionHandler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException.class) public org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorResponse> handleMethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ex)
      Handles invalid path or query parameter type conversions.
      Parameters:
      ex - the type mismatch exception
      Returns:
      bad request response describing the invalid parameter
    • handleMissingRequestCookieException

      @ExceptionHandler(org.springframework.web.bind.MissingRequestCookieException.class) public org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorResponse> handleMissingRequestCookieException(org.springframework.web.bind.MissingRequestCookieException ignored)
      Handles missing refresh token cookies on auth endpoints that require them.
      Parameters:
      ignored - the missing cookie exception
      Returns:
      unauthorized response indicating the refresh token is missing