refactor: GlobalExceptionHandler에서 커스텀 예외는 INFO 로그로 기록하도록 수정

This commit is contained in:
이상진 2025-10-07 22:17:01 +09:00
parent 1902fc6f7c
commit 979623a670

View File

@ -30,7 +30,7 @@ class GlobalExceptionHandler(
val httpStatus: HttpStatus = errorCode.httpStatus
val errorResponse = CommonErrorResponse(errorCode)
logException(servletRequest, httpStatus, errorResponse, e)
log.info { convertExceptionLogMessage(servletRequest, httpStatus, errorResponse, e) }
return ResponseEntity
.status(httpStatus.value())
@ -56,7 +56,7 @@ class GlobalExceptionHandler(
val httpStatus: HttpStatus = errorCode.httpStatus
val errorResponse = CommonErrorResponse(errorCode)
logException(servletRequest, httpStatus, errorResponse, e)
log.warn { convertExceptionLogMessage(servletRequest, httpStatus, errorResponse, e) }
return ResponseEntity
.status(httpStatus.value())
@ -74,28 +74,26 @@ class GlobalExceptionHandler(
val httpStatus: HttpStatus = errorCode.httpStatus
val errorResponse = CommonErrorResponse(errorCode)
logException(servletRequest, httpStatus, errorResponse, e)
log.warn { convertExceptionLogMessage(servletRequest, httpStatus, errorResponse, e) }
return ResponseEntity
.status(httpStatus.value())
.body(errorResponse)
}
private fun logException(
private fun convertExceptionLogMessage(
servletRequest: HttpServletRequest,
httpStatus: HttpStatus,
errorResponse: CommonErrorResponse,
exception: Exception
) {
): String {
val actualException: Exception? = if (errorResponse.message == exception.message) null else exception
val logMessage = messageConverter.convertToErrorResponseMessage(
return messageConverter.convertToErrorResponseMessage(
servletRequest = servletRequest,
httpStatus = httpStatus,
responseBody = errorResponse,
exception = actualException
)
log.warn { logMessage }
}
}