generated from pricelees/issue-pr-template
[#56] 예약 & 결제 프로세스 및 패키지 구조 재정의 #57
@ -1,6 +1,5 @@
|
|||||||
package com.sangdol.common.web.exception
|
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.CommonErrorCode
|
||||||
import com.sangdol.common.types.exception.ErrorCode
|
import com.sangdol.common.types.exception.ErrorCode
|
||||||
import com.sangdol.common.types.exception.RoomescapeException
|
import com.sangdol.common.types.exception.RoomescapeException
|
||||||
@ -88,13 +87,11 @@ class GlobalExceptionHandler(
|
|||||||
errorResponse: CommonErrorResponse,
|
errorResponse: CommonErrorResponse,
|
||||||
exception: Exception
|
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 actualException: Exception? = if (errorResponse.message == exception.message) null else exception
|
||||||
|
|
||||||
val logMessage = messageConverter.convertToResponseMessage(
|
val logMessage = messageConverter.convertToErrorResponseMessage(
|
||||||
type = type,
|
|
||||||
servletRequest = servletRequest,
|
servletRequest = servletRequest,
|
||||||
httpStatusCode = httpStatus.value(),
|
httpStatus = httpStatus,
|
||||||
responseBody = errorResponse,
|
responseBody = errorResponse,
|
||||||
exception = actualException
|
exception = actualException
|
||||||
)
|
)
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package com.sangdol.common.web.support.log
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
import com.sangdol.common.log.constant.LogType
|
import com.sangdol.common.log.constant.LogType
|
||||||
|
import com.sangdol.common.types.web.HttpStatus
|
||||||
import jakarta.servlet.http.HttpServletRequest
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
|
|
||||||
class WebLogMessageConverter(
|
class WebLogMessageConverter(
|
||||||
@ -49,4 +50,19 @@ class WebLogMessageConverter(
|
|||||||
|
|
||||||
return objectMapper.writeValueAsString(payload)
|
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
|
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