Skip to content

Commit

Permalink
Fikse riktig httpstatus (401) for manglende autentisering ved å fjern…
Browse files Browse the repository at this point in the history
…e overordnet håndtering av Exception.class
  • Loading branch information
s148719 committed Oct 10, 2023
1 parent 0719396 commit bf117da
Showing 1 changed file with 5 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package no.nav.bidrag.behandling.controller

import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.exc.InvalidFormatException
import mu.KotlinLogging
import org.springframework.core.Ordered
import org.springframework.core.annotation.Order
import org.springframework.core.convert.ConversionFailedException
Expand All @@ -17,8 +16,6 @@ import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.client.HttpStatusCodeException
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException

private val log = KotlinLogging.logger {}

@Order(Ordered.HIGHEST_PRECEDENCE)
@ControllerAdvice
@Suppress("unused")
Expand Down Expand Up @@ -58,16 +55,6 @@ class ExceptionHandler {
.build<Any>()
}

@ResponseBody
@ExceptionHandler(Exception::class)
fun handleOtherExceptions(exception: Exception): ResponseEntity<*> {
log.warn("Det skjedde en ukjent feil", exception)
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.header(HttpHeaders.WARNING, "Det skjedde en ukjent feil: ${exception.message}")
.build<Any>()
}

private fun getErrorMessage(exception: HttpStatusCodeException): String {
val errorMessage = StringBuilder()
errorMessage.append("Det skjedde en feil ved kall mot ekstern tjeneste: ")
Expand Down Expand Up @@ -96,7 +83,11 @@ class ExceptionHandler {
return error
}

data class Error(val status: Int, val message: String, val fieldErrors: MutableList<CustomFieldError> = mutableListOf()) {
data class Error(
val status: Int,
val message: String,
val fieldErrors: MutableList<CustomFieldError> = mutableListOf()
) {
fun addFieldError(
objectName: String,
field: String,
Expand Down

0 comments on commit bf117da

Please sign in to comment.