generated from pricelees/issue-pr-template
[#56] 예약 & 결제 프로세스 및 패키지 구조 재정의 #57
@ -0,0 +1,40 @@
|
|||||||
|
package com.sangdol.roomescape.payment.exception
|
||||||
|
|
||||||
|
import com.sangdol.common.types.web.CommonErrorResponse
|
||||||
|
import com.sangdol.common.web.support.log.WebLogMessageConverter
|
||||||
|
import io.github.oshai.kotlinlogging.KLogger
|
||||||
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
|
import jakarta.servlet.http.HttpServletRequest
|
||||||
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||||
|
import org.springframework.web.bind.annotation.RestControllerAdvice
|
||||||
|
|
||||||
|
private val log: KLogger = KotlinLogging.logger {}
|
||||||
|
|
||||||
|
@RestControllerAdvice
|
||||||
|
class PaymentExceptionHandler(
|
||||||
|
private val logMessageConverter: WebLogMessageConverter
|
||||||
|
) {
|
||||||
|
@ExceptionHandler(PaymentException::class)
|
||||||
|
fun handlePaymentException(
|
||||||
|
servletRequest: HttpServletRequest,
|
||||||
|
e: PaymentException
|
||||||
|
): ResponseEntity<CommonErrorResponse> {
|
||||||
|
val errorCode = e.errorCode
|
||||||
|
val httpStatus = errorCode.httpStatus
|
||||||
|
val errorResponse = CommonErrorResponse(errorCode, e.message)
|
||||||
|
|
||||||
|
log.warn {
|
||||||
|
logMessageConverter.convertToErrorResponseMessage(
|
||||||
|
servletRequest = servletRequest,
|
||||||
|
httpStatus = httpStatus,
|
||||||
|
responseBody = errorResponse,
|
||||||
|
exception = if (e.message == errorCode.message) null else e
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResponseEntity
|
||||||
|
.status(httpStatus.value())
|
||||||
|
.body(errorResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user