feat: Improve error handling
This commit is contained in:
@@ -5,6 +5,7 @@ import org.slf4j.LoggerFactory
|
|||||||
import org.springframework.http.HttpStatus
|
import org.springframework.http.HttpStatus
|
||||||
import org.springframework.http.MediaType
|
import org.springframework.http.MediaType
|
||||||
import org.springframework.http.ResponseEntity
|
import org.springframework.http.ResponseEntity
|
||||||
|
import org.springframework.http.converter.HttpMessageNotReadableException
|
||||||
import org.springframework.web.bind.annotation.ControllerAdvice
|
import org.springframework.web.bind.annotation.ControllerAdvice
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler
|
import org.springframework.web.bind.annotation.ExceptionHandler
|
||||||
import org.springframework.web.bind.annotation.ResponseBody
|
import org.springframework.web.bind.annotation.ResponseBody
|
||||||
@@ -51,6 +52,24 @@ class ExceptionHandler {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ResponseBody
|
||||||
|
@ExceptionHandler(HttpMessageNotReadableException::class)
|
||||||
|
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||||
|
fun handleHttpMessageNotReadableException(e: HttpMessageNotReadableException): ResponseEntity<ProblemDetails> {
|
||||||
|
logger.warn("Failed to read HTTP message", e)
|
||||||
|
return ResponseEntity
|
||||||
|
.status(HttpStatus.BAD_REQUEST)
|
||||||
|
.contentType(MediaType.APPLICATION_PROBLEM_JSON)
|
||||||
|
.body(
|
||||||
|
ProblemDetails(
|
||||||
|
title = "Bad Request",
|
||||||
|
status = HttpStatus.BAD_REQUEST.value(),
|
||||||
|
type = URI.create("about:blank"),
|
||||||
|
detail = e.message ?: "Invalid request body",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ExceptionHandler(UserAlreadyExistsException::class)
|
@ExceptionHandler(UserAlreadyExistsException::class)
|
||||||
@ResponseStatus(HttpStatus.CONFLICT)
|
@ResponseStatus(HttpStatus.CONFLICT)
|
||||||
|
|||||||
@@ -31,5 +31,6 @@ logging:
|
|||||||
springframework:
|
springframework:
|
||||||
security: TRACE
|
security: TRACE
|
||||||
oauth2: TRACE
|
oauth2: TRACE
|
||||||
|
web: DEBUG
|
||||||
org.testcontainers: INFO
|
org.testcontainers: INFO
|
||||||
com.github.dockerjava: WARN
|
com.github.dockerjava: WARN
|
||||||
|
|||||||
@@ -38,10 +38,3 @@ spring:
|
|||||||
jwt:
|
jwt:
|
||||||
issuer-uri: http://localhost:7080/realms/legalconsenthub
|
issuer-uri: http://localhost:7080/realms/legalconsenthub
|
||||||
jwk-set-uri: http://localhost:7080/realms/legalconsenthub/protocol/openid-connect/certs
|
jwk-set-uri: http://localhost:7080/realms/legalconsenthub/protocol/openid-connect/certs
|
||||||
|
|
||||||
logging:
|
|
||||||
level:
|
|
||||||
org:
|
|
||||||
springframework:
|
|
||||||
security: TRACE
|
|
||||||
oauth2: TRACE
|
|
||||||
|
|||||||
Reference in New Issue
Block a user