From 66c1213bdf13f5039e086f713bc15e5ceff866ed Mon Sep 17 00:00:00 2001 From: Magnus Rinnan Date: Fri, 18 Oct 2024 13:44:04 +0200 Subject: [PATCH] Justeringer logging skattegrunnlag --- .../grunnlag/exception/RestExceptionHandler.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/kotlin/no/nav/bidrag/grunnlag/exception/RestExceptionHandler.kt b/src/main/kotlin/no/nav/bidrag/grunnlag/exception/RestExceptionHandler.kt index 3bb2a742..1d31ef3a 100644 --- a/src/main/kotlin/no/nav/bidrag/grunnlag/exception/RestExceptionHandler.kt +++ b/src/main/kotlin/no/nav/bidrag/grunnlag/exception/RestExceptionHandler.kt @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonMappingException import com.fasterxml.jackson.databind.exc.InvalidFormatException import no.nav.bidrag.commons.ExceptionLogger import no.nav.bidrag.commons.util.LoggingRetryListener +import org.slf4j.LoggerFactory import org.springframework.core.ParameterizedTypeReference import org.springframework.http.HttpEntity import org.springframework.http.HttpHeaders @@ -31,6 +32,7 @@ import org.springframework.web.client.HttpStatusCodeException import org.springframework.web.client.RestClientException import org.springframework.web.client.RestTemplate import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException +import org.springframework.web.server.ResponseStatusException import java.net.SocketTimeoutException import java.time.format.DateTimeParseException @@ -38,6 +40,8 @@ import java.time.format.DateTimeParseException @Component class RestExceptionHandler(private val exceptionLogger: ExceptionLogger) { + private val logger = LoggerFactory.getLogger(this::class.java) + @ResponseBody @ExceptionHandler(RestClientException::class) protected fun handleRestClientException(e: RestClientException): ResponseEntity<*> { @@ -110,6 +114,7 @@ class RestExceptionHandler(private val exceptionLogger: ExceptionLogger) { else -> e.originalMessage } } + else -> { errors["Feil ved deserialisering"] = e.originalMessage } @@ -117,6 +122,18 @@ class RestExceptionHandler(private val exceptionLogger: ExceptionLogger) { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errors) } + @ResponseBody + @ExceptionHandler( + ResponseStatusException::class, + ) + fun handleResponseStatusExceptions(e: ResponseStatusException): ResponseEntity<*> { + logger.warn("Feil ved hent av grunllag: ${e.message}") + val feilmelding = "Hent av grunnlag feilet!" + val headers = HttpHeaders() + headers.add(HttpHeaders.WARNING, feilmelding) + return ResponseEntity.status(e.statusCode).body(ResponseEntity(e.message, headers, e.statusCode)) + } + private fun extractPath(paths: List): String { val sb = StringBuilder() paths.forEach { jsonMappingException -> @@ -137,6 +154,7 @@ sealed class RestResponse { data class Success(val body: T) : RestResponse() data class Failure(val message: String?, val statusCode: HttpStatusCode, val restClientException: Exception) : RestResponse() } + fun httpRetryTemplate(details: String? = null): RetryTemplate { val retryTemplate = RetryTemplate() val fixedBackOffPolicy = FixedBackOffPolicy()