Skip to content

Commit

Permalink
F - Exception håntering av call mot eux-rina-api
Browse files Browse the repository at this point in the history
  • Loading branch information
dskarpas committed Aug 22, 2024
1 parent 5a5a8e9 commit 6516441
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/main/kotlin/no/nav/eessi/pensjon/api/geo/KodeverkService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,36 @@ import no.nav.eessi.pensjon.utils.toJson
import org.slf4j.LoggerFactory
import org.springframework.http.*
import org.springframework.stereotype.Service
import org.springframework.web.client.HttpStatusCodeException
import org.springframework.web.client.RestTemplate
import org.springframework.web.server.ResponseStatusException

@Service
class KodeverkService(private val euxNavIdentRestTemplate: RestTemplate) {

private val logger = LoggerFactory.getLogger(KodeverkService::class.java)

fun getLandkoderAkseptertAvRina(format: String? = null): String? {
val url = "/cpi/landkoder/rina"
logger.debug("KodeverkService getLandkoderAkseptertAvRina: $url ")
val url = "/cpi/landkoder/rina${format?.let { "?format=$it" } ?: ""}"
logger.debug("KodeverkService getLandkoderAkseptertAvRina: $url")

val response: ResponseEntity<String> = euxNavIdentRestTemplate.exchange(
if (format != null) "$url?format=$format" else url,
HttpMethod.GET,
HttpEntity<String>(HttpHeaders().apply {
contentType = MediaType.APPLICATION_JSON
}),
String::class.java
)
logger.debug("""getLandkoderAkseptertAvRina response body:
| url: $url
| response: ${response.toJson()}""".trimMargin())
return response.body
return try {
val response = euxNavIdentRestTemplate.exchange(
url,
HttpMethod.GET,
HttpEntity<String>(HttpHeaders().apply {
contentType = MediaType.APPLICATION_JSON
}),
String::class.java
)
logger.debug("Hent landkode API, response: ${response.toJson()}".trimMargin())
response.body
} catch (e: HttpStatusCodeException) {
logger.error("HttpStatusCodeException oppstod under henting av landkoder: ${e.message}")
throw RuntimeException(e)
} catch (e: Exception) {
logger.error("En feil oppstod under henting av landkoder: ${e.message}")
throw RuntimeException(e)
}
}
}

0 comments on commit 6516441

Please sign in to comment.