Skip to content

Commit

Permalink
Fix 404 exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
enstulen committed Feb 14, 2024
1 parent 547fa4f commit c0c94ed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum class ErrorCode(val value: String) {
GENERAL_ERROR("GENERAL_ERROR"), // generell feilmelding "noe gikk galt"
AUTH_ERROR("AUTH_ERROR"), // feilmelding for autentisering
TOKEN_EMAIL_MISSING("TOKEN_EMAIL_MISSING"), // kan ikke hente ut epost fra token
NOT_FOUND("NOT_FOUND"), // ressurs ikke funnet

// EREG
EREG_UNAUTHORIZED("EREG_UNAUTHORIZED"), // ikke autentisert for å hente data fra ereg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,18 @@ class ControllerAdvice {
@ExceptionHandler(value = [ClientErrorNotFoundException::class, NoResourceFoundException::class])
fun notFoundErrorResponse(
request: HttpServletRequest,
ex: ClientErrorNotFoundException
ex: Exception
): ResponseEntity<ErrorResponse> {
log.warn("Feil i kall til {}: ({}) {}", request.requestURI, ex.errorCode.value, ex.message, ex)
if (ex is ClientErrorNotFoundException) {
log.warn("Feil i kall til {}: ({}) {}", request.requestURI, ex.errorCode.value, ex.message, ex)
return ResponseEntity
.status(HttpStatus.NOT_FOUND)
.body(ErrorResponse(ex.message, ex.errorCode.value))
}
log.warn("Feil i kall til {}: {}", request.requestURI, ex.message, ex)
return ResponseEntity
.status(HttpStatus.NOT_FOUND)
.body(ErrorResponse(ex.message, ex.errorCode.value))
.body(ErrorResponse(ex.message, ErrorCode.NOT_FOUND.value))
}

// 500
Expand Down

0 comments on commit c0c94ed

Please sign in to comment.