Class GlobalMailSenderExceptionHandler

java.lang.Object
com.app.controller.exceptionsHandler.GlobalMailSenderExceptionHandler

@RestControllerAdvice public class GlobalMailSenderExceptionHandler extends Object
Global exception handler for email sending related exceptions. Catches various Spring Mail exceptions and returns appropriate HTTP responses with standardized error messages.
  • Constructor Details

    • GlobalMailSenderExceptionHandler

      public GlobalMailSenderExceptionHandler()
  • Method Details

    • handleMailAuthException

      @ExceptionHandler(org.springframework.mail.MailAuthenticationException.class) @ResponseStatus(UNAUTHORIZED) public ResponseDto<String> handleMailAuthException(Exception e)
      Handles SMTP authentication failures. Returns HTTP 401 UNAUTHORIZED.
      Parameters:
      e - the MailAuthenticationException indicating SMTP auth failure
      Returns:
      a response with an authentication failure message
    • handleMailSendException

      @ExceptionHandler(org.springframework.mail.MailSendException.class) @ResponseStatus(FAILED_DEPENDENCY) public ResponseDto<String> handleMailSendException(org.springframework.mail.MailSendException e)
      Handles failures in sending email to one or more recipients. Returns HTTP 424 FAILED DEPENDENCY.
      Parameters:
      e - the MailSendException containing failed messages details
      Returns:
      a response indicating partial email send failure
    • handleMailValidationException

      @ExceptionHandler({org.springframework.mail.MailPreparationException.class,org.springframework.mail.MailParseException.class}) @ResponseStatus(BAD_REQUEST) public ResponseDto<String> handleMailValidationException(org.springframework.mail.MailPreparationException e)
      Handles email message preparation or parsing errors, typically due to invalid message format. Returns HTTP 400 BAD REQUEST.
      Parameters:
      e - the MailPreparationException or MailParseException describing validation failure
      Returns:
      a response with details about the invalid email message
    • handleGenericMailException

      @ExceptionHandler(org.springframework.mail.MailException.class) @ResponseStatus(INTERNAL_SERVER_ERROR) public ResponseDto<String> handleGenericMailException(org.springframework.mail.MailException e)
      Handles all other generic MailExceptions not covered by specific handlers. Returns HTTP 500 INTERNAL SERVER ERROR.
      Parameters:
      e - the generic MailException
      Returns:
      a response indicating an internal email service error