generated from pricelees/issue-pr-template
[#56] 예약 & 결제 프로세스 및 패키지 구조 재정의 #57
@ -1,6 +1,5 @@
|
||||
package com.sangdol.common.web.exception
|
||||
|
||||
import com.sangdol.common.log.constant.LogType
|
||||
import com.sangdol.common.types.exception.CommonErrorCode
|
||||
import com.sangdol.common.types.exception.ErrorCode
|
||||
import com.sangdol.common.types.exception.RoomescapeException
|
||||
@ -88,13 +87,11 @@ class GlobalExceptionHandler(
|
||||
errorResponse: CommonErrorResponse,
|
||||
exception: Exception
|
||||
) {
|
||||
val type = if (httpStatus.isClientError()) LogType.APPLICATION_FAILURE else LogType.UNHANDLED_EXCEPTION
|
||||
val actualException: Exception? = if (errorResponse.message == exception.message) null else exception
|
||||
|
||||
val logMessage = messageConverter.convertToResponseMessage(
|
||||
type = type,
|
||||
val logMessage = messageConverter.convertToErrorResponseMessage(
|
||||
servletRequest = servletRequest,
|
||||
httpStatusCode = httpStatus.value(),
|
||||
httpStatus = httpStatus,
|
||||
responseBody = errorResponse,
|
||||
exception = actualException
|
||||
)
|
||||
|
||||
@ -2,6 +2,7 @@ package com.sangdol.common.web.support.log
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.sangdol.common.log.constant.LogType
|
||||
import com.sangdol.common.types.web.HttpStatus
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
|
||||
class WebLogMessageConverter(
|
||||
@ -49,4 +50,19 @@ class WebLogMessageConverter(
|
||||
|
||||
return objectMapper.writeValueAsString(payload)
|
||||
}
|
||||
|
||||
fun convertToErrorResponseMessage(
|
||||
servletRequest: HttpServletRequest,
|
||||
httpStatus: HttpStatus,
|
||||
responseBody: Any? = null,
|
||||
exception: Exception? = null,
|
||||
): String {
|
||||
val type = if (httpStatus.isClientError()) {
|
||||
LogType.APPLICATION_FAILURE
|
||||
} else {
|
||||
LogType.UNHANDLED_EXCEPTION
|
||||
}
|
||||
|
||||
return convertToResponseMessage(type, servletRequest, httpStatus.value(), responseBody, exception)
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,5 +168,27 @@ class WebLogMessageConverterTest : FunSpec({
|
||||
this["exception"] shouldBe null
|
||||
}
|
||||
}
|
||||
|
||||
test("4xx 에러가 발생하면 ${LogType.APPLICATION_FAILURE} 타입으로 변환한다.") {
|
||||
val result = converter.convertToErrorResponseMessage(
|
||||
servletRequest = servletRequest,
|
||||
httpStatus = HttpStatus.BAD_REQUEST,
|
||||
)
|
||||
|
||||
assertSoftly(objectMapper.readValue(result, LinkedHashMap::class.java)) {
|
||||
this["type"] shouldBe LogType.APPLICATION_FAILURE.name
|
||||
}
|
||||
}
|
||||
|
||||
test("5xx 에러가 발생하면 ${LogType.UNHANDLED_EXCEPTION} 타입으로 변환한다.") {
|
||||
val result = converter.convertToErrorResponseMessage(
|
||||
servletRequest = servletRequest,
|
||||
httpStatus = HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
)
|
||||
|
||||
assertSoftly(objectMapper.readValue(result, LinkedHashMap::class.java)) {
|
||||
this["type"] shouldBe LogType.UNHANDLED_EXCEPTION.name
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user