Class GlobalExceptionHandler

java.lang.Object
org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
com.order.api01authgateway.exception.GlobalExceptionHandler
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.context.MessageSourceAware

@RestControllerAdvice public class GlobalExceptionHandler extends org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler
Centralized exception handling component using RestControllerAdvice.

Maps application-specific exceptions to ProblemDetail objects compliant with RFC 7807 (Problem Details for HTTP APIs).

  • 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.ProblemDetail
    handleAuthenticationException(org.springframework.security.core.AuthenticationException ex)
    Handles general AuthenticationException and maps it to a 401 Unauthorized response.
    org.springframework.http.ProblemDetail
    handleBadCredentials(org.springframework.security.authentication.BadCredentialsException ex)
    Handles BadCredentialsException and maps it to a 401 Unauthorized response.
    org.springframework.http.ProblemDetail
    Handles unexpected Exception occurrences and maps them to a 500 Internal Server Error response.

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

    createProblemDetail, createResponseEntity, getMessageSource, handleAsyncRequestTimeoutException, handleBindException, handleConversionNotSupported, handleErrorResponseException, handleException, handleExceptionInternal, handleHandlerMethodValidationException, handleHttpMediaTypeNotAcceptable, handleHttpMediaTypeNotSupported, handleHttpMessageNotReadable, handleHttpMessageNotWritable, handleHttpRequestMethodNotSupported, handleMaxUploadSizeExceededException, handleMethodArgumentNotValid, 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

    • GlobalExceptionHandler

      public GlobalExceptionHandler()
  • Method Details

    • handleBadCredentials

      @ExceptionHandler(org.springframework.security.authentication.BadCredentialsException.class) public org.springframework.http.ProblemDetail handleBadCredentials(org.springframework.security.authentication.BadCredentialsException ex)
      Handles BadCredentialsException and maps it to a 401 Unauthorized response.
      Parameters:
      ex - The exception encountered.
      Returns:
      A ProblemDetail describing the error.
    • handleAuthenticationException

      @ExceptionHandler(org.springframework.security.core.AuthenticationException.class) public org.springframework.http.ProblemDetail handleAuthenticationException(org.springframework.security.core.AuthenticationException ex)
      Handles general AuthenticationException and maps it to a 401 Unauthorized response.
      Parameters:
      ex - The exception encountered.
      Returns:
      A ProblemDetail describing the error.
    • handleGeneralException

      @ExceptionHandler(java.lang.Exception.class) public org.springframework.http.ProblemDetail handleGeneralException(Exception ex)
      Handles unexpected Exception occurrences and maps them to a 500 Internal Server Error response.
      Parameters:
      ex - The exception encountered.
      Returns:
      A ProblemDetail describing the error.