From 5af787b4b34a04de816ab83e82c1b3be8fc7f027 Mon Sep 17 00:00:00 2001 From: hoa0217 Date: Thu, 7 Mar 2024 01:54:14 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20GlobalExceptionHandler=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 추가된 Exception handle 메서드 추가 --- .../common/GlobalExceptionHandler.java | 111 +++++++++--------- .../exception/InvalidHourException.java | 8 -- 2 files changed, 57 insertions(+), 62 deletions(-) delete mode 100644 src/main/java/com/modoospace/common/exception/InvalidHourException.java diff --git a/src/main/java/com/modoospace/common/GlobalExceptionHandler.java b/src/main/java/com/modoospace/common/GlobalExceptionHandler.java index 86443d5..b4df0aa 100644 --- a/src/main/java/com/modoospace/common/GlobalExceptionHandler.java +++ b/src/main/java/com/modoospace/common/GlobalExceptionHandler.java @@ -1,14 +1,6 @@ package com.modoospace.common; -import com.modoospace.common.exception.AlarmSendException; -import com.modoospace.common.exception.ConflictingReservationException; -import com.modoospace.common.exception.ConflictingTimeException; -import com.modoospace.common.exception.DuplicatedWeekdayException; -import com.modoospace.common.exception.InvalidTimeRangeException; -import com.modoospace.common.exception.NotFoundEntityException; -import com.modoospace.common.exception.NotOpenedFacilityException; -import com.modoospace.common.exception.PermissionDeniedException; -import com.modoospace.common.exception.SSEConnectError; +import com.modoospace.common.exception.*; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; @@ -17,57 +9,68 @@ @RestControllerAdvice public class GlobalExceptionHandler { - @ExceptionHandler(AlarmSendException.class) - public ResponseEntity handleAlarmSendException( - InvalidTimeRangeException exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } + @ExceptionHandler(AlarmSendException.class) + public ResponseEntity handleAlarmSendException(InvalidTimeRangeException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } - @ExceptionHandler(ConflictingReservationException.class) - public ResponseEntity handleConflictingReservationException( - ConflictingReservationException exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.CONFLICT); - } + @ExceptionHandler(SSEConnectError.class) + public ResponseEntity handleSSEConnectError(SSEConnectError exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } - @ExceptionHandler(ConflictingTimeException.class) - public ResponseEntity handleConflictingTimeException( - ConflictingTimeException exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.CONFLICT); - } + @ExceptionHandler(RedisProcessingException.class) + public ResponseEntity handleRedisProcessingException(SSEConnectError exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } - @ExceptionHandler(DuplicatedWeekdayException.class) - public ResponseEntity handleDuplicatedWeekdayException( - ConflictingTimeException exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.CONFLICT); - } + @ExceptionHandler(ConflictingReservationException.class) + public ResponseEntity handleConflictingReservationException(ConflictingReservationException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.CONFLICT); + } - @ExceptionHandler(InvalidTimeRangeException.class) - public ResponseEntity handleInvalidTimeRangeException( - InvalidTimeRangeException exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST); - } + @ExceptionHandler(ConflictingTimeException.class) + public ResponseEntity handleConflictingTimeException(ConflictingTimeException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.CONFLICT); + } - @ExceptionHandler(NotFoundEntityException.class) - public ResponseEntity handleNotFoundEntityException( - NotFoundEntityException exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND); - } + @ExceptionHandler(DuplicatedWeekdayException.class) + public ResponseEntity handleDuplicatedWeekdayException(ConflictingTimeException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.CONFLICT); + } - @ExceptionHandler(NotOpenedFacilityException.class) - public ResponseEntity handleNotOpenedFacilityException( - NotOpenedFacilityException exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST); - } + @ExceptionHandler(PermissionDeniedException.class) + public ResponseEntity handlePermissionDeniedException(PermissionDeniedException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.FORBIDDEN); + } - @ExceptionHandler(PermissionDeniedException.class) - public ResponseEntity handlePermissionDeniedException( - PermissionDeniedException exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.FORBIDDEN); - } + @ExceptionHandler(NotFoundEntityException.class) + public ResponseEntity handleNotFoundEntityException(NotFoundEntityException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.NOT_FOUND); + } - @ExceptionHandler(SSEConnectError.class) - public ResponseEntity handleSSEConnectError( - SSEConnectError exception) { - return new ResponseEntity<>(exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } + @ExceptionHandler(InvalidTimeRangeException.class) + public ResponseEntity handleInvalidTimeRangeException(InvalidTimeRangeException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(NotOpenedFacilityException.class) + public ResponseEntity handleNotOpenedFacilityException(NotOpenedFacilityException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(DeleteSpaceWithFacilitiesException.class) + public ResponseEntity handleDeleteSpaceWithFacilitiesException(DeleteSpaceWithFacilitiesException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(InvalidNumOfUserException.class) + public ResponseEntity handleInvalidNumOfUserException(InvalidNumOfUserException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(LimitNumOfUserException.class) + public ResponseEntity handleLimitNumOfUserException(LimitNumOfUserException exception) { + return new ResponseEntity<>(exception.getMessage(), HttpStatus.BAD_REQUEST); + } } diff --git a/src/main/java/com/modoospace/common/exception/InvalidHourException.java b/src/main/java/com/modoospace/common/exception/InvalidHourException.java deleted file mode 100644 index ab5040a..0000000 --- a/src/main/java/com/modoospace/common/exception/InvalidHourException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.modoospace.common.exception; - -public class InvalidHourException extends RuntimeException { - - public InvalidHourException(Integer hour) { - super("올바른 시간이 아닙니다.(" + hour + ")"); - } -}