java.lang.Object
com.finconsgroup.itserr.marketplace.usercommunication.dm.exception.MessagingExceptionHandler

@ControllerAdvice public class MessagingExceptionHandler extends Object
  • Constructor Details

    • MessagingExceptionHandler

      public MessagingExceptionHandler()
  • Method Details

    • handleMethodArgumentNotValidException

      @SendToUser("/queue/errors") @MessageExceptionHandler(org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException.class) public MessagingErrorResponseDto handleMethodArgumentNotValidException(org.springframework.messaging.handler.annotation.support.MethodArgumentNotValidException ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor)
      Handles exceptions thrown when validation errors on method arguments occur.
      Parameters:
      ex - the exception thrown, the type of exception is MethodArgumentNotValidException
      headerAccessor - the header accessor
      Returns:
      a response dto with bad request status and validation error messages
    • handleMessagingException

      @SendToUser("/queue/errors") @ExceptionHandler(org.springframework.messaging.MessagingException.class) public MessagingErrorResponseDto handleMessagingException(org.springframework.messaging.MessagingException ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor)
      Handles generic messaging exceptions.
      Parameters:
      ex - the exception thrown, the type of exception is MessagingException
      headerAccessor - the header accessor
      Returns:
      a response dto with an internal server error status and empty message
    • logError

      public void logError(Exception ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor)
      Logs the given exception with a formatted error message.
      Parameters:
      ex - the exception to log
      headerAccessor - the header accessor
    • createError

      public MessagingErrorResponseDto createError(org.springframework.http.HttpStatus httpStatus, String message, Exception ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor)
      Creates a ResponseEntity containing a single error message.
      Parameters:
      httpStatus - the HTTP status to set in the response
      message - the error message to include
      ex - the thrown exception
      headerAccessor - the header accessor
      Returns:
      a response entity with the specified HTTP status and error message
    • createError

      public MessagingErrorResponseDto createError(org.springframework.http.HttpStatus httpStatus, List<String> messages, Exception ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor)
      Creates a ResponseEntity containing multiple error messages.
      Parameters:
      httpStatus - the HTTP status to set in the response
      messages - the list of error messages to include
      ex - the thrown exception
      headerAccessor - the header accessor
      Returns:
      a response dto with the specified HTTP status and error messages