generated from pricelees/issue-pr-template
feat: LoggingFilter에서 예외 방어 코드 추가
This commit is contained in:
parent
957996baf6
commit
021b2bae56
@ -11,6 +11,7 @@ import org.springframework.stereotype.Component
|
||||
import org.springframework.web.filter.OncePerRequestFilter
|
||||
import org.springframework.web.util.ContentCachingRequestWrapper
|
||||
import org.springframework.web.util.ContentCachingResponseWrapper
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
private val log = KotlinLogging.logger {}
|
||||
|
||||
@ -54,12 +55,20 @@ class LoggingFilter(
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
request.contentAsByteArray.takeIf { it.isNotEmpty() }
|
||||
?.let { payload["request_body"] = objectMapper.readValue(it, Map::class.java) }
|
||||
?.let { payload["request_body"] = parseContent(it) }
|
||||
|
||||
response.contentAsByteArray.takeIf { it.isNotEmpty() }
|
||||
?.let { payload["response_body"] = objectMapper.readValue(it, Map::class.java) }
|
||||
?.let { payload["response_body"] = parseContent(it) }
|
||||
}
|
||||
|
||||
log.info { objectMapper.writeValueAsString(payload) }
|
||||
}
|
||||
|
||||
private fun parseContent(content: ByteArray): Any {
|
||||
return try {
|
||||
objectMapper.readValue(content, Map::class.java)
|
||||
} catch (_: Exception) {
|
||||
String(content, StandardCharsets.UTF_8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user