Skip to content

Commit fa75c32

Browse files
committed
Legg på logging kontekst og logging av body til sikkerlogg ved feil
1 parent b8e9993 commit fa75c32

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/mapping/MapFromGUIInntekt.kt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package no.nav.dagpenger.inntekt.mapping
22

3+
import mu.KotlinLogging
34
import no.nav.dagpenger.inntekt.db.DetachedInntekt
45
import no.nav.dagpenger.inntekt.db.StoredInntekt
56
import no.nav.dagpenger.inntekt.inntektskomponenten.v1.ArbeidsInntektInformasjon
@@ -8,7 +9,9 @@ import no.nav.dagpenger.inntekt.inntektskomponenten.v1.Inntekt
89
import no.nav.dagpenger.inntekt.inntektskomponenten.v1.InntektkomponentResponse
910
import no.nav.dagpenger.inntekt.inntektskomponenten.v1.TilleggInformasjon
1011
import no.nav.dagpenger.inntekt.inntektskomponenten.v1.TilleggInformasjonsDetaljer
11-
import java.lang.IllegalArgumentException
12+
13+
private val logg = KotlinLogging.logger {}
14+
private val sikkerlogg = KotlinLogging.logger("tjenestekall.MapFromGUIInntekt")
1215

1316
fun mapToStoredInntekt(guiInntekt: GUIInntekt): StoredInntekt = guiInntekt.inntektId?.let {
1417
StoredInntekt(
@@ -20,7 +23,10 @@ fun mapToStoredInntekt(guiInntekt: GUIInntekt): StoredInntekt = guiInntekt.innte
2023
),
2124
guiInntekt.manueltRedigert
2225
)
23-
} ?: throw IllegalArgumentException("missing innktektId")
26+
} ?: throw IllegalArgumentException("missing innktektId").also {
27+
logg.error(it) { "Mangler inntektId" }
28+
sikkerlogg.error(it) { "Mangler inntektId. guiInntekt=$guiInntekt" }
29+
}
2430

2531
fun mapToDetachedInntekt(guiInntekt: GUIInntekt): DetachedInntekt =
2632
DetachedInntekt(
@@ -60,7 +66,15 @@ private fun mapToArbeidsInntektMaaneder(arbeidsMaaneder: List<GUIArbeidsInntektM
6066
inntekt.utloeserArbeidsgiveravgift,
6167
inntekt.informasjonsstatus,
6268
datagrunnlagForVerdikode.type,
63-
datagrunnlagForVerdikode.forhold?.let { TilleggInformasjon(inntekt.tilleggsinformasjon?.kategori, TilleggInformasjonsDetaljer(inntekt.tilleggsinformasjon?.tilleggsinformasjonDetaljer?.detaljerType, it)) }
69+
datagrunnlagForVerdikode.forhold?.let {
70+
TilleggInformasjon(
71+
inntekt.tilleggsinformasjon?.kategori,
72+
TilleggInformasjonsDetaljer(
73+
inntekt.tilleggsinformasjon?.tilleggsinformasjonDetaljer?.detaljerType,
74+
it
75+
)
76+
)
77+
}
6478
)
6579
} ?: emptyList()
6680
)

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/v1/UklassifisertInntektRoute.kt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fun Route.uklassifisertInntekt(
6262
route("/uklassifisert/{aktørId}/{kontekstType}/{kontekstId}/{beregningsDato}") {
6363
get {
6464
withContext(Dispatchers.IO) {
65-
parseUrlPathParameters().run {
65+
withInntektRequest {
6666
inntektStore.getInntektId(
6767
Inntektparametre(
6868
aktørId = this.aktørId,
@@ -83,7 +83,7 @@ fun Route.uklassifisertInntekt(
8383
}
8484
post {
8585
withContext(Dispatchers.IO) {
86-
parseUrlPathParameters().run {
86+
withInntektRequest {
8787
val guiInntekt = call.receive<GUIInntekt>()
8888
mapToStoredInntekt(guiInntekt).let {
8989
inntektStore.storeInntekt(
@@ -121,7 +121,7 @@ fun Route.uklassifisertInntekt(
121121
get {
122122
val callId = call.callId
123123
withContext(Dispatchers.IO) {
124-
parseUrlPathParameters().run {
124+
withInntektRequest {
125125
withLoggingContext(
126126
"route" to "/uklassifisert/uncached",
127127
"aktørId" to aktørId,
@@ -151,7 +151,7 @@ fun Route.uklassifisertInntekt(
151151

152152
post {
153153
withContext(Dispatchers.IO) {
154-
parseUrlPathParameters().run {
154+
withInntektRequest {
155155
val guiInntekt = call.receive<GUIInntekt>()
156156
mapToDetachedInntekt(guiInntekt).let {
157157
inntektStore.storeInntekt(
@@ -209,14 +209,23 @@ private fun PipelineContext<Unit, ApplicationCall>.getSubject(): String {
209209
}
210210
}
211211

212-
private fun PipelineContext<Unit, ApplicationCall>.parseUrlPathParameters(): InntektRequest = runCatching {
213-
InntektRequest(
214-
aktørId = call.parameters["aktørId"]!!,
215-
kontekstId = call.parameters["kontekstId"]!!,
216-
kontekstType = call.parameters["kontekstType"]!!,
217-
beregningsDato = LocalDate.parse(call.parameters["beregningsDato"]!!)
218-
)
219-
}.getOrElse { t -> throw IllegalArgumentException("Failed to parse parameters", t) }
212+
private inline fun PipelineContext<Unit, ApplicationCall>.withInntektRequest(block: InntektRequest.() -> Unit) {
213+
val inntektRequest = runCatching {
214+
InntektRequest(
215+
aktørId = call.parameters["aktørId"]!!,
216+
kontekstId = call.parameters["kontekstId"]!!,
217+
kontekstType = call.parameters["kontekstType"]!!,
218+
beregningsDato = LocalDate.parse(call.parameters["beregningsDato"]!!)
219+
)
220+
}.getOrElse { t -> throw IllegalArgumentException("Failed to parse parameters", t) }
221+
222+
withLoggingContext(
223+
"kontekstId" to inntektRequest.kontekstId,
224+
"kontekstType" to inntektRequest.kontekstType
225+
) {
226+
block(inntektRequest)
227+
}
228+
}
220229

221230
data class InntektRequest(
222231
val aktørId: String,

0 commit comments

Comments
 (0)