Skip to content

Commit

Permalink
add exception handling for ping pre2025
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfofanov committed Dec 3, 2024
1 parent aea7d05 commit 515912f
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import no.nav.tjenestepensjon.simulering.model.domain.TPOrdningIdDto
import no.nav.tjenestepensjon.simulering.v2.models.domain.SivilstandCodeEnum
import no.nav.tjenestepensjon.simulering.v2.models.request.*
import no.nav.tjenestepensjon.simulering.v2.models.response.SimulerOffentligTjenestepensjonResponse
import no.nav.tjenestepensjon.simulering.v2025.tjenestepensjon.v1.exception.TjenestepensjonSimuleringException
import org.springframework.stereotype.Service
import org.springframework.web.reactive.function.client.WebClient
import org.springframework.web.reactive.function.client.WebClientRequestException
import org.springframework.web.reactive.function.client.WebClientResponseException
import org.springframework.web.reactive.function.client.bodyToMono
import java.time.LocalDate

Expand All @@ -27,14 +30,25 @@ class RestClient(private val spkPre2025Client: WebClient) {
fun ping(): String {
val request = dummyRequest()
val url = "/nav/pensjon/prognose/v1"
log.info { "Pinging SPK at url https://api.prod.spk.no$url with request $request" }
return spkPre2025Client
.post()
.uri(url)
.bodyValue(request)
.retrieve()
.bodyToMono(String::class.java)
.block() ?: "No body received"
log.info { "Pinging SPK at url $url with request $request" }
return try {
spkPre2025Client
.post()
.uri(url)
.bodyValue(request)
.retrieve()
.bodyToMono(String::class.java)
.block() ?: "No body received"
} catch (e: WebClientResponseException){
val msg = "Failed to ping SPK at url $url, got: ${e.responseBodyAsString} for request $request, ${e.message}"
log.error(e) { msg }
msg
} catch (e: WebClientRequestException){
val msg = "Failed to ping SPK at uri ${e.uri} with request $request"
log.error(e) { msg }
msg
}

}

private fun dummyRequest(fnr: String = "14866297763"): DummyRequestV2 {
Expand Down

0 comments on commit 515912f

Please sign in to comment.