Class MessagingExceptionHandler
java.lang.Object
com.finconsgroup.itserr.marketplace.usercommunication.dm.exception.MessagingExceptionHandler
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateError(org.springframework.http.HttpStatus httpStatus, String message, Exception ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor) Creates aResponseEntitycontaining a single error message.createError(org.springframework.http.HttpStatus httpStatus, List<String> messages, Exception ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor) Creates aResponseEntitycontaining multiple error messages.handleMessagingException(org.springframework.messaging.MessagingException ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor) Handles generic messaging exceptions.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.voidLogs the given exception with a formatted error message.
-
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 isMethodArgumentNotValidExceptionheaderAccessor- 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 isMessagingExceptionheaderAccessor- 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 logheaderAccessor- the header accessor
-
createError
public MessagingErrorResponseDto createError(org.springframework.http.HttpStatus httpStatus, String message, Exception ex, org.springframework.messaging.simp.SimpMessageHeaderAccessor headerAccessor) Creates aResponseEntitycontaining a single error message.- Parameters:
httpStatus- the HTTP status to set in the responsemessage- the error message to includeex- the thrown exceptionheaderAccessor- 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 aResponseEntitycontaining multiple error messages.- Parameters:
httpStatus- the HTTP status to set in the responsemessages- the list of error messages to includeex- the thrown exceptionheaderAccessor- the header accessor- Returns:
- a response dto with the specified HTTP status and error messages
-