Class APIExceptionHandler
java.lang.Object
com.nicholasalfonso.lato.security.APIExceptionHandler
Centralized exception handler that maps common API failures to JSON error responses.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordError payload containing a summary message and field-level validation details.static final recordSimple error payload containing a single message.static final recordValidation error for a single request field. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<APIExceptionHandler.ErrorDetailsResponse> handleArgumentNotValidException(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles request body validation failures from Bean Validation annotations.org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorResponse> handleHttpRequestMethodNotSupportedException(org.springframework.web.HttpRequestMethodNotSupportedException ex) Handles unsupported HTTP method usage on a route.org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorResponse> handleMethodArgumentTypeMismatchException(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ex) Handles invalid path or query parameter type conversions.org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorResponse> handleMissingRequestCookieException(org.springframework.web.bind.MissingRequestCookieException ignored) Handles missing refresh token cookies on auth endpoints that require them.org.springframework.http.ResponseEntity<APIExceptionHandler.ErrorResponse> handleResponseStatusException(org.springframework.web.server.ResponseStatusException ex) Handles explicit HTTP status exceptions thrown by application services.
-
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
-