Skip to content

Commit 30d447e

Browse files
authored
Merge pull request #666 from navikt/SecureLogForKode6And7
Flytter alt av logging for kode 6 og 7 til secureLogger
2 parents cae7b0f + 9986b89 commit 30d447e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/main/kotlin/no/nav/medlemskap/common/ExceptionHandler.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import no.nav.medlemskap.common.exceptions.*
1616
import v1.mt_1067_nav.no.udi.HentPersonstatusFault
1717

1818
private val logger = KotlinLogging.logger { }
19+
private val secureLogger = KotlinLogging.logger("tjenestekall")
1920

2021
fun StatusPagesConfig.exceptionHandler() {
2122
exception<GraphqlError> { call, cause ->
@@ -78,7 +79,7 @@ fun StatusPagesConfig.exceptionHandler() {
7879
}
7980
exception<GradertAdresseException> { call, cause ->
8081

81-
call.logWarningAndRespond(cause, HttpStatusCode.ServiceUnavailable) {
82+
call.logSecureWarningAndRespond(cause, HttpStatusCode.ServiceUnavailable) {
8283
"GradertAdresse. Lovme skal ikke kalles for personer med kode 6/7"
8384
}
8485
}
@@ -149,6 +150,26 @@ private suspend inline fun ApplicationCall.logWarningAndRespond(
149150
)
150151
this.respond(status, response)
151152
}
153+
private suspend inline fun ApplicationCall.logSecureWarningAndRespond(
154+
cause: Throwable,
155+
status: HttpStatusCode = HttpStatusCode.InternalServerError,
156+
lazyMessage: () -> String
157+
) {
158+
val message = lazyMessage()
159+
secureLogger.warn(
160+
message,
161+
kv("cause", cause),
162+
kv("callId", callId)
163+
)
164+
val response = HttpErrorResponse(
165+
url = this.request.uri,
166+
cause = cause.toString(),
167+
message = message,
168+
code = status,
169+
callId = getCorrelationId(callId)
170+
)
171+
this.respond(status, response)
172+
}
152173

153174
internal data class HttpErrorResponse(
154175
val url: String,

0 commit comments

Comments
 (0)