Skip to content

Commit

Permalink
Merge pull request #666 from navikt/SecureLogForKode6And7
Browse files Browse the repository at this point in the history
Flytter alt av logging for kode 6 og 7 til secureLogger
  • Loading branch information
hjmNav authored Jul 2, 2024
2 parents cae7b0f + 9986b89 commit 30d447e
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/main/kotlin/no/nav/medlemskap/common/ExceptionHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import no.nav.medlemskap.common.exceptions.*
import v1.mt_1067_nav.no.udi.HentPersonstatusFault

private val logger = KotlinLogging.logger { }
private val secureLogger = KotlinLogging.logger("tjenestekall")

fun StatusPagesConfig.exceptionHandler() {
exception<GraphqlError> { call, cause ->
Expand Down Expand Up @@ -78,7 +79,7 @@ fun StatusPagesConfig.exceptionHandler() {
}
exception<GradertAdresseException> { call, cause ->

call.logWarningAndRespond(cause, HttpStatusCode.ServiceUnavailable) {
call.logSecureWarningAndRespond(cause, HttpStatusCode.ServiceUnavailable) {
"GradertAdresse. Lovme skal ikke kalles for personer med kode 6/7"
}
}
Expand Down Expand Up @@ -149,6 +150,26 @@ private suspend inline fun ApplicationCall.logWarningAndRespond(
)
this.respond(status, response)
}
private suspend inline fun ApplicationCall.logSecureWarningAndRespond(
cause: Throwable,
status: HttpStatusCode = HttpStatusCode.InternalServerError,
lazyMessage: () -> String
) {
val message = lazyMessage()
secureLogger.warn(
message,
kv("cause", cause),
kv("callId", callId)
)
val response = HttpErrorResponse(
url = this.request.uri,
cause = cause.toString(),
message = message,
code = status,
callId = getCorrelationId(callId)
)
this.respond(status, response)
}

internal data class HttpErrorResponse(
val url: String,
Expand Down

0 comments on commit 30d447e

Please sign in to comment.