From 90c1cff233a4a14acb92b5517e8bc596670bf5bc Mon Sep 17 00:00:00 2001 From: pricelees Date: Sun, 27 Jul 2025 22:39:41 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20ExceptionHandler=EC=97=90=EC=84=9C?= =?UTF-8?q?=EC=9D=98=20=EB=A1=9C=EA=B9=85=20=EB=B0=A9=EC=8B=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 커스텀 예외(RoomescapeException)은 로깅 X -> 에러 발생 지점에서 기록 - Exception인 경우에만 stacktrace 기록 --- .../exception/ExceptionControllerAdvice.kt | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/roomescape/common/exception/ExceptionControllerAdvice.kt b/src/main/kotlin/roomescape/common/exception/ExceptionControllerAdvice.kt index 2a877347..5037d01d 100644 --- a/src/main/kotlin/roomescape/common/exception/ExceptionControllerAdvice.kt +++ b/src/main/kotlin/roomescape/common/exception/ExceptionControllerAdvice.kt @@ -11,48 +11,46 @@ import roomescape.common.dto.response.CommonErrorResponse @RestControllerAdvice class ExceptionControllerAdvice( - private val logger: KLogger = KotlinLogging.logger {} + private val log: KLogger = KotlinLogging.logger {} ) { @ExceptionHandler(value = [RoomescapeException::class]) fun handleRoomException(e: RoomescapeException): ResponseEntity { - logger.error(e) { "message: ${e.message}" } - val errorCode: ErrorCode = e.errorCode return ResponseEntity - .status(errorCode.httpStatus) - .body(CommonErrorResponse(errorCode, e.message)) + .status(errorCode.httpStatus) + .body(CommonErrorResponse(errorCode, e.message)) } @ExceptionHandler(value = [HttpMessageNotReadableException::class]) fun handleHttpMessageNotReadableException(e: HttpMessageNotReadableException): ResponseEntity { - logger.error(e) { "message: ${e.message}" } + log.debug { "message: ${e.message}" } val errorCode: ErrorCode = CommonErrorCode.INVALID_INPUT_VALUE return ResponseEntity - .status(errorCode.httpStatus) - .body(CommonErrorResponse(errorCode)) + .status(errorCode.httpStatus) + .body(CommonErrorResponse(errorCode)) } @ExceptionHandler(value = [MethodArgumentNotValidException::class]) fun handleMethodArgumentNotValidException(e: MethodArgumentNotValidException): ResponseEntity { val message: String = e.bindingResult.allErrors - .mapNotNull { it.defaultMessage } - .joinToString(", ") - logger.error(e) { "message: $message" } + .mapNotNull { it.defaultMessage } + .joinToString(", ") + log.debug { "message: $message" } val errorCode: ErrorCode = CommonErrorCode.INVALID_INPUT_VALUE return ResponseEntity - .status(errorCode.httpStatus) - .body(CommonErrorResponse(errorCode)) + .status(errorCode.httpStatus) + .body(CommonErrorResponse(errorCode)) } @ExceptionHandler(value = [Exception::class]) fun handleException(e: Exception): ResponseEntity { - logger.error(e) { "message: ${e.message}" } + log.error(e) { "message: ${e.message}" } val errorCode: ErrorCode = CommonErrorCode.UNEXPECTED_SERVER_ERROR return ResponseEntity - .status(errorCode.httpStatus) - .body(CommonErrorResponse(errorCode)) + .status(errorCode.httpStatus) + .body(CommonErrorResponse(errorCode)) } }