Class GlobalExceptionHandler
java.lang.Object
com.loomcache.springboot.controller.GlobalExceptionHandler
Global exception handler for all REST controllers.
Maps domain exceptions to appropriate HTTP status codes and structured error responses. More specific exception handlers take precedence over general ones.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordStructured error response returned to clients. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleAccessDenied(org.springframework.security.access.AccessDeniedException ex) Handles authorization failures from method security.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> Handles authentication failures.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> Handles bad request errors from illegal arguments.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> Handles type mismatch errors in request payloads.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> Catch-all handler for unexpected exceptions.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> Handles all other LoomCache-specific exceptions.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleMalformedJson(org.springframework.http.converter.HttpMessageNotReadableException ex) Handles malformed JSON request bodies.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleMethodNotAllowed(org.springframework.web.HttpRequestMethodNotSupportedException ex) Handles unsupported HTTP method errors.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleMissingParam(org.springframework.web.bind.MissingServletRequestParameterException ex) Handles missing required request parameters.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> Handles requests sent to a non-leader node.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> Handles invalid number format in request parameters.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleSecurityAuth(org.springframework.security.core.AuthenticationException ex) Handles Spring Security authentication failures.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> Handles operation timeout errors.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleTypeMismatch(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ex) Handles type mismatch errors in request parameters.org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleValidationError(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles bean validation failures from @Valid annotations.
-
Constructor Details
-
GlobalExceptionHandler
public GlobalExceptionHandler()
-
-
Method Details
-
handleBadRequest
@ExceptionHandler(IllegalArgumentException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleBadRequest(IllegalArgumentException ex) Handles bad request errors from illegal arguments.- Parameters:
ex- the exception- Returns:
- 400 Bad Request response
-
handleTypeMismatch
@ExceptionHandler(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleTypeMismatch(org.springframework.web.method.annotation.MethodArgumentTypeMismatchException ex) Handles type mismatch errors in request parameters.- Parameters:
ex- the exception- Returns:
- 400 Bad Request response
-
handleMethodNotAllowed
@ExceptionHandler(org.springframework.web.HttpRequestMethodNotSupportedException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleMethodNotAllowed(org.springframework.web.HttpRequestMethodNotSupportedException ex) Handles unsupported HTTP method errors.- Parameters:
ex- the exception- Returns:
- 405 Method Not Allowed response
-
handleClassCast
@ExceptionHandler(ClassCastException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleClassCast(ClassCastException ex) Handles type mismatch errors in request payloads.- Parameters:
ex- the exception- Returns:
- 400 Bad Request response
-
handleNumberFormat
@ExceptionHandler(NumberFormatException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleNumberFormat(NumberFormatException ex) Handles invalid number format in request parameters.- Parameters:
ex- the exception- Returns:
- 400 Bad Request response
-
handleAuth
@ExceptionHandler(AuthenticationException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleAuth(AuthenticationException ex) Handles authentication failures.- Parameters:
ex- the exception- Returns:
- 401 Unauthorized response
-
handleSecurityAuth
@ExceptionHandler(org.springframework.security.core.AuthenticationException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleSecurityAuth(org.springframework.security.core.AuthenticationException ex) Handles Spring Security authentication failures.- Parameters:
ex- the exception- Returns:
- 401 Unauthorized response
-
handleAccessDenied
@ExceptionHandler(org.springframework.security.access.AccessDeniedException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleAccessDenied(org.springframework.security.access.AccessDeniedException ex) Handles authorization failures from method security.- Parameters:
ex- the exception- Returns:
- 403 Forbidden response
-
handleNotLeader
@ExceptionHandler(NotLeaderException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleNotLeader(NotLeaderException ex) Handles requests sent to a non-leader node.- Parameters:
ex- the exception- Returns:
- 503 Service Unavailable response
-
handleTimeout
@ExceptionHandler(TimeoutException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleTimeout(TimeoutException ex) Handles operation timeout errors.- Parameters:
ex- the exception- Returns:
- 504 Gateway Timeout response
-
handleLoomException
@ExceptionHandler(LoomException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleLoomException(LoomException ex) Handles all other LoomCache-specific exceptions.- Parameters:
ex- the exception- Returns:
- 500 Internal Server Error response
-
handleValidationError
@ExceptionHandler(org.springframework.web.bind.MethodArgumentNotValidException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleValidationError(org.springframework.web.bind.MethodArgumentNotValidException ex) Handles bean validation failures from @Valid annotations.- Parameters:
ex- the exception- Returns:
- 400 Bad Request response
-
handleMalformedJson
@ExceptionHandler(org.springframework.http.converter.HttpMessageNotReadableException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleMalformedJson(org.springframework.http.converter.HttpMessageNotReadableException ex) Handles malformed JSON request bodies.- Parameters:
ex- the exception- Returns:
- 400 Bad Request response
-
handleMissingParam
@ExceptionHandler(org.springframework.web.bind.MissingServletRequestParameterException.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleMissingParam(org.springframework.web.bind.MissingServletRequestParameterException ex) Handles missing required request parameters.- Parameters:
ex- the exception- Returns:
- 400 Bad Request response
-
handleGeneric
@ExceptionHandler(Exception.class) public org.springframework.http.ResponseEntity<GlobalExceptionHandler.ErrorResponse> handleGeneric(Exception ex) Catch-all handler for unexpected exceptions.- Parameters:
ex- the exception- Returns:
- 500 Internal Server Error response
-