Skip to content

Commit 75ef08e

Browse files
Gustav Lillesæteravoldsund
andcommitted
Håndtering av exceptions og meldinger fra oebs
Co-authored-by: avoldsund <[email protected]>
1 parent 56fcfeb commit 75ef08e

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/main/kotlin/no/nav/hjelpemidler/Application.kt

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,37 @@ fun main() {
7070
} catch (e: Exception) {
7171
// Deal with invalid json in request
7272
sikkerlogg.info("Parsing incoming json request failed with exception (responding 4xx): $e")
73-
e.printStackTrace()
7473
SensuMetrics().feilVedMeldingFraOebs()
7574
call.respond(HttpStatusCode.BadRequest, "bad request: json not valid")
7675
return@post
7776
}
7877

79-
val uid = UUID.randomUUID()
80-
val opprettet = LocalDateTime.now()
78+
if (validJson!!.incidentType != "Vedtak Infotrygd") {
79+
log.info("Mottok melding fra oebs av incidentType: ${validJson.incidentType}. Avbryter prosesseringen og returnerer")
80+
call.respond(HttpStatusCode.OK)
81+
return@post
82+
}
8183

82-
// Publish the received json to our rapid
83-
rapidApp!!.publish(
84-
UUID.randomUUID().toString(),
85-
"{\"@id\": \"$uid\", \"@event_name\": \"oebs-listener-testevent\", \"@opprettet\": \"$opprettet\", \"fnrBruker\": ${validJson?.accountNumber} \"data\": ${
86-
Klaxon().toJsonString(
87-
validJson
88-
)
89-
}}"
84+
val melding = Message(
85+
UUID.randomUUID(),
86+
"hm-ordrelinje",
87+
LocalDateTime.now(),
88+
validJson.accountNumber,
89+
validJson
9090
)
9191

92-
call.respond(HttpStatusCode.OK, "ok")
92+
// Publish the received json to our rapid
93+
try {
94+
rapidApp!!.publish(validJson.accountNumber, Klaxon().toJsonString(melding))
95+
SensuMetrics().meldingTilRapidSuksess()
96+
} catch (e: Exception) {
97+
SensuMetrics().meldingTilRapidFeilet()
98+
sikkerlogg.error("Sending til rapid feilet, exception: $e")
99+
call.respond(HttpStatusCode.InternalServerError, "Feil under prosessering")
100+
return@post
101+
}
102+
103+
call.respond(HttpStatusCode.OK)
93104
}
94105
}
95106
}.build().apply {
@@ -102,6 +113,14 @@ fun main() {
102113
logg.info("Application ending.")
103114
}
104115

116+
data class Message(
117+
val eventId: UUID,
118+
val eventName: String,
119+
val opprettet: LocalDateTime,
120+
val fnrBruker: String,
121+
val data: Statusinfo,
122+
)
123+
105124
data class Statusinfo(
106125
val system: String,
107126
@Json(name = "IncidentNummer")

src/main/kotlin/no/nav/hjelpemidler/metrics/SensuMetrics.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ class SensuMetrics {
3737
registerPoint(OEBS_MELDING_FEIL, mapOf("counter" to 1L), emptyMap())
3838
}
3939

40-
fun test() {
41-
println("writing to sensu")
42-
registerPoint("testing", mapOf("counter" to 1L), emptyMap())
43-
}
44-
4540
private fun registerPoint(measurement: String, fields: Map<String, Any>, tags: Map<String, String>) {
4641
log.info("Posting point to Influx: measurment {} fields {} tags {} ", measurement, fields, tags)
4742
val point = Point.measurement(measurement)
@@ -51,7 +46,11 @@ class SensuMetrics {
5146
.fields(fields)
5247
.build()
5348

54-
sendEvent(SensuEvent(sensuName, point.lineProtocol()))
49+
try {
50+
sendEvent(SensuEvent(sensuName, point.lineProtocol()))
51+
} catch (e: Exception) {
52+
log.error("Feil ved sending til Sensu: eventname: $measurement")
53+
}
5554
}
5655

5756
private fun sendEvent(sensuEvent: SensuEvent) {

0 commit comments

Comments
 (0)