Class EnduranceTrioExceptionHandlerAPI

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
com.endurancetrio.app.common.handler.EnduranceTrioExceptionHandlerAPI
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.MessageSourceAware

@RestControllerAdvice(annotations=EnduranceTrioRestController.class) public class EnduranceTrioExceptionHandlerAPI extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
The EnduranceTrioExceptionHandlerAPI class is a global exception handler for the EnduranceTrio application.

This class interceptor captures:

  • Domain-specific EnduranceTrioException
  • Standard Spring Web exceptions (Validation, JSON parsing)
  • Generic unhandled exceptions
All exceptions are transformed into a standardized EnduranceTrioResponse.
  • Field Summary

    Fields inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

    logger, PAGE_NOT_FOUND_LOG_CATEGORY, pageNotFoundLogger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.springframework.http.ResponseEntity<Object>
    handleConstraintViolation(jakarta.validation.ConstraintViolationException ex)
    Intercepts validation failures from the business layer or manual validation triggers.
    org.springframework.http.ResponseEntity<Object>
    handleDataIntegrity(org.springframework.dao.DataIntegrityViolationException ex)
    Intercepts database integrity violations, such as unique constraint conflicts or foreign key violations.
    org.springframework.http.ResponseEntity<@NonNull Object>
    Handles business logic exceptions defined within the EnduranceTrio domain.
    protected org.springframework.http.ResponseEntity<@NonNull Object>
    handleHandlerMethodValidationException(@NonNull org.springframework.web.method.annotation.HandlerMethodValidationException exception, @NonNull org.springframework.http.HttpHeaders headers, @NonNull org.springframework.http.HttpStatusCode status, @NonNull org.springframework.web.context.request.WebRequest request)
    Intercepts validation failures on method-level parameters such as @PathVariable or @RequestParam.
    protected org.springframework.http.ResponseEntity<@NonNull Object>
    handleHttpMessageNotReadable(@NonNull org.springframework.http.converter.HttpMessageNotReadableException exception, @NonNull org.springframework.http.HttpHeaders headers, @NonNull org.springframework.http.HttpStatusCode status, @NonNull org.springframework.web.context.request.WebRequest request)
    Intercepts malformed JSON requests where the payload cannot be deserialized.
    protected org.springframework.http.ResponseEntity<@NonNull Object>
    handleMethodArgumentNotValid(@NonNull org.springframework.web.bind.MethodArgumentNotValidException exception, @NonNull org.springframework.http.HttpHeaders headers, @NonNull org.springframework.http.HttpStatusCode status, @NonNull org.springframework.web.context.request.WebRequest request)
    Intercepts validation failures for @Valid annotated @RequestBody objects.
    org.springframework.http.ResponseEntity<@NonNull EnduranceTrioResponse<String>>
    Catch-all handler for any unexpected system exceptions.

    Methods inherited from class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler

    createProblemDetail, createResponseEntity, getMessageSource, handleAsyncRequestNotUsableException, handleAsyncRequestTimeoutException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMaxUploadSizeExceededException, handleMethodValidationException, handleMissingPathVariable, handleMissingServletRequestParameter, handleMissingServletRequestPart, handleNoHandlerFoundException, handleNoResourceFoundException, handleServletRequestBindingException, handleTypeMismatch, setMessageSource

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EnduranceTrioExceptionHandlerAPI

      public EnduranceTrioExceptionHandlerAPI()
  • Method Details

    • handleHttpMessageNotReadable

      protected org.springframework.http.ResponseEntity<@NonNull Object> handleHttpMessageNotReadable(@NonNull org.springframework.http.converter.HttpMessageNotReadableException exception, @NonNull org.springframework.http.HttpHeaders headers, @NonNull org.springframework.http.HttpStatusCode status, @NonNull org.springframework.web.context.request.WebRequest request)
      Intercepts malformed JSON requests where the payload cannot be deserialized.
      Overrides:
      handleHttpMessageNotReadable in class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
      Returns:
      a ResponseEntity containing a EnduranceTrioError BAD_REQUEST error.
    • handleHandlerMethodValidationException

      protected org.springframework.http.ResponseEntity<@NonNull Object> handleHandlerMethodValidationException(@NonNull org.springframework.web.method.annotation.HandlerMethodValidationException exception, @NonNull org.springframework.http.HttpHeaders headers, @NonNull org.springframework.http.HttpStatusCode status, @NonNull org.springframework.web.context.request.WebRequest request)
      Intercepts validation failures on method-level parameters such as @PathVariable or @RequestParam.
      Overrides:
      handleHandlerMethodValidationException in class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
      Returns:
      a ResponseEntity containing a list of parameter validation errors.
    • handleMethodArgumentNotValid

      protected org.springframework.http.ResponseEntity<@NonNull Object> handleMethodArgumentNotValid(@NonNull org.springframework.web.bind.MethodArgumentNotValidException exception, @NonNull org.springframework.http.HttpHeaders headers, @NonNull org.springframework.http.HttpStatusCode status, @NonNull org.springframework.web.context.request.WebRequest request)
      Intercepts validation failures for @Valid annotated @RequestBody objects.
      Overrides:
      handleMethodArgumentNotValid in class org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
      Returns:
      a ResponseEntity containing a list of field-level validation errors.
    • handleConstraintViolation

      @ExceptionHandler(jakarta.validation.ConstraintViolationException.class) public org.springframework.http.ResponseEntity<Object> handleConstraintViolation(jakarta.validation.ConstraintViolationException ex)
      Intercepts validation failures from the business layer or manual validation triggers.
      Returns:
      a ResponseEntity containing the constraint violations.
    • handleDataIntegrity

      @ExceptionHandler(org.springframework.dao.DataIntegrityViolationException.class) public org.springframework.http.ResponseEntity<Object> handleDataIntegrity(org.springframework.dao.DataIntegrityViolationException ex)
      Intercepts database integrity violations, such as unique constraint conflicts or foreign key violations.

      This often occurs in the data layer when the state of the database prevents the requested persistence operation.

      Parameters:
      ex - The data integrity violation exception.
      Returns:
      a ResponseEntity mapped to a concurrency or conflict error.
    • handledException

      @ExceptionHandler(EnduranceTrioException.class) public org.springframework.http.ResponseEntity<@NonNull Object> handledException(EnduranceTrioException exception)
      Handles business logic exceptions defined within the EnduranceTrio domain. This is the primary funnel for all expected error states.
      Parameters:
      exception - The domain exception containing error codes and messages.
      Returns:
      a standardized EnduranceTrioResponse.
    • unhandledException

      @ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ResponseEntity<@NonNull EnduranceTrioResponse<String>> unhandledException(Exception exception)
      Catch-all handler for any unexpected system exceptions. Maps unknown errors to a standard HTTP 500 Internal Server Error to avoid leaking system details.
      Parameters:
      exception - The unexpected throwable.
      Returns:
      a ResponseEntity with a generic error message.