diff --git a/src/main/kotlin/roomescape/common/exception/ExceptionControllerAdvice.kt b/src/main/kotlin/roomescape/common/exception/ExceptionControllerAdvice.kt index 1f892236..90276979 100644 --- a/src/main/kotlin/roomescape/common/exception/ExceptionControllerAdvice.kt +++ b/src/main/kotlin/roomescape/common/exception/ExceptionControllerAdvice.kt @@ -9,11 +9,21 @@ import org.springframework.web.bind.MethodArgumentNotValidException import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.RestControllerAdvice import roomescape.common.dto.response.CommonErrorResponse +import roomescape.common.dto.response.CommonErrorResponseV2 @RestControllerAdvice class ExceptionControllerAdvice( private val logger: KLogger = KotlinLogging.logger {} ) { + @ExceptionHandler(value = [RoomescapeExceptionV2::class]) + fun handleRoomException(e: RoomescapeExceptionV2): ResponseEntity { + logger.error(e) { "message: ${e.message}" } + + val errorCode: ErrorCode = e.errorCode + val httpStatus: Int = errorCode.httpStatus.value() + return ResponseEntity.status(httpStatus) + .body(CommonErrorResponseV2(errorCode, e.message)) + } @ExceptionHandler(value = [RoomescapeException::class]) fun handleRoomEscapeException(e: RoomescapeException): ResponseEntity {