Skip to content

Commit

Permalink
Legge til navn på roller
Browse files Browse the repository at this point in the history
  • Loading branch information
s148719 committed Nov 14, 2023
1 parent 8e21ded commit 99af4b0
Show file tree
Hide file tree
Showing 37 changed files with 1,175 additions and 900 deletions.
Empty file added .editorconfig
Empty file.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@ Et lokalt Dockermiljø må være tilgjengelig for lokal kjøring. Forebredelsess
> docker-compose build \
> docker-compose up
#### Bygge applikasjonen

###### Maven wrapper
Maven wrapper sikrer at alle Maven bygg-forutsetninger er til stede. For å benytte Maven wrapper kjør
> mvn wrapper:wrapper
deretter kan Maven-kommandoer som clean install kjøres med
> ./mvnw clean install
###### Ktlint med Maven wrapper
verifisere
> ./mvnw antrun:run@ktlint
formattere
> ./mvnw antrun:run@ktlint-format
#### Starte applikasjon lokalt

Profil: local (angis i program arguments)
Expand Down
14 changes: 9 additions & 5 deletions src/main/kotlin/no/nav/bidrag/behandling/Exceptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ fun behandlingNotFoundException(behandlingId: Long): Nothing =

class KunneIkkeLeseMeldingFraHendelse(melding: String?, throwable: Throwable) : RuntimeException(melding, throwable)

fun fantIkkeSak(saksnummer: String): Nothing = throw HttpClientErrorException(
HttpStatus.BAD_REQUEST,
"Sak med saksnummer $saksnummer finnes ikke",
)
fun fantIkkeSak(saksnummer: String): Nothing =
throw HttpClientErrorException(
HttpStatus.BAD_REQUEST,
"Sak med saksnummer $saksnummer finnes ikke",
)

fun fantIkkeFødselsdatoTilSøknadsbarn(behandlingsid: Long): Nothing =
throw HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, "Fant ikke fødselsdato til søknadsbarn i behandling med id $behandlingsid")
throw HttpClientErrorException(
HttpStatus.INTERNAL_SERVER_ERROR,
"Fant ikke fødselsdato til søknadsbarn i behandling med id $behandlingsid",
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ class DefaultRestControllerAdvice {
)
fun handleInvalidValueExceptions(exception: Exception): ResponseEntity<*> {
val cause = exception.cause
val valideringsFeil = if (cause is MissingKotlinParameterException) {
createMissingKotlinParameterViolation(
cause,
)
} else {
null
}
val valideringsFeil =
if (cause is MissingKotlinParameterException) {
createMissingKotlinParameterViolation(
cause,
)
} else {
null
}
LOGGER.warn(
"Forespørselen inneholder ugyldig verdi: ${valideringsFeil ?: "ukjent feil"}",
exception,
Expand Down Expand Up @@ -71,23 +72,28 @@ class DefaultRestControllerAdvice {
@ExceptionHandler(Exception::class)
fun handleOtherExceptions(exception: Exception): ResponseEntity<*> {
LOGGER.warn("Det skjedde en ukjent feil", exception)
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).header(HttpHeaders.WARNING, "Det skjedde en ukjent feil: ${exception.message}")
return ResponseEntity.status(
HttpStatus.INTERNAL_SERVER_ERROR,
).header(HttpHeaders.WARNING, "Det skjedde en ukjent feil: ${exception.message}")
.build<Any>()
}

@ResponseBody
@ExceptionHandler(JwtTokenUnauthorizedException::class)
fun handleUnauthorizedException(exception: JwtTokenUnauthorizedException): ResponseEntity<*> {
LOGGER.warn("Ugyldig eller manglende sikkerhetstoken", exception)
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).header(HttpHeaders.WARNING, "Ugyldig eller manglende sikkerhetstoken").build<Any>()
return ResponseEntity.status(
HttpStatus.UNAUTHORIZED,
).header(HttpHeaders.WARNING, "Ugyldig eller manglende sikkerhetstoken").build<Any>()
}

private fun createMissingKotlinParameterViolation(ex: MissingKotlinParameterException): String {
val errorFieldRegex = Regex("\\.([^.]*)\\[\\\"(.*)\"\\]\$")
val paths = ex.path.map { errorFieldRegex.find(it.description)!! }.map {
val (objectName, field) = it.destructured
"$objectName.$field"
}
val paths =
ex.path.map { errorFieldRegex.find(it.description)!! }.map {
val (objectName, field) = it.destructured
"$objectName.$field"
}
return "${paths.joinToString("->")} må fylles ut"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import org.aspectj.lang.annotation.Aspect
import org.aspectj.lang.annotation.Before
import org.slf4j.MDC
import org.springframework.stereotype.Component
import java.util.*
import java.util.UUID

private val log = KotlinLogging.logger {}

@Component
@Aspect
class HendelseCorrelationAspect(private val objectMapper: ObjectMapper) {
@Before(value = "execution(* no.nav.bidrag.behandling.kafka.VedtakHendelseListener.prossesserVedtakHendelse(..)) && args(hendelse)")
fun leggSporingFraVedtakHendelseTilMDC(joinPoint: JoinPoint, hendelse: ConsumerRecord<String, String>) {
fun leggSporingFraVedtakHendelseTilMDC(
joinPoint: JoinPoint,
hendelse: ConsumerRecord<String, String>,
) {
hentSporingFraHendelse(hendelse)?.let {
val correlationId = CorrelationId.existing(it)
MDC.put(CORRELATION_ID_HEADER, correlationId.get())
Expand Down
Loading

0 comments on commit 99af4b0

Please sign in to comment.