feat: 새로 추가된 커스텀 예외 핸들링 추가

This commit is contained in:
이상진 2025-07-23 13:50:57 +09:00
parent c6a5927b72
commit 75afa45224

View File

@ -9,11 +9,21 @@ import org.springframework.web.bind.MethodArgumentNotValidException
import org.springframework.web.bind.annotation.ExceptionHandler import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice import org.springframework.web.bind.annotation.RestControllerAdvice
import roomescape.common.dto.response.CommonErrorResponse import roomescape.common.dto.response.CommonErrorResponse
import roomescape.common.dto.response.CommonErrorResponseV2
@RestControllerAdvice @RestControllerAdvice
class ExceptionControllerAdvice( class ExceptionControllerAdvice(
private val logger: KLogger = KotlinLogging.logger {} private val logger: KLogger = KotlinLogging.logger {}
) { ) {
@ExceptionHandler(value = [RoomescapeExceptionV2::class])
fun handleRoomException(e: RoomescapeExceptionV2): ResponseEntity<CommonErrorResponseV2> {
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]) @ExceptionHandler(value = [RoomescapeException::class])
fun handleRoomEscapeException(e: RoomescapeException): ResponseEntity<CommonErrorResponse> { fun handleRoomEscapeException(e: RoomescapeException): ResponseEntity<CommonErrorResponse> {