From 3fb4c227d69cecb96cbe91b59f4eae247fc7bf02 Mon Sep 17 00:00:00 2001 From: Florian RICHER Date: Tue, 2 Jan 2024 22:57:16 +0100 Subject: [PATCH] Change errors formatter with field: error format --- .../com/example/demo/exceptions/GlobalExceptionHandler.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/example/demo/exceptions/GlobalExceptionHandler.kt b/src/main/kotlin/com/example/demo/exceptions/GlobalExceptionHandler.kt index 02c0fb2..a3d86b8 100644 --- a/src/main/kotlin/com/example/demo/exceptions/GlobalExceptionHandler.kt +++ b/src/main/kotlin/com/example/demo/exceptions/GlobalExceptionHandler.kt @@ -16,13 +16,11 @@ import java.util.stream.Collectors class GlobalExceptionHandler : ResponseEntityExceptionHandler() { override fun handleMethodArgumentNotValid(ex: MethodArgumentNotValidException, headers: HttpHeaders, status: HttpStatusCode, request: WebRequest): ResponseEntity? { - val body: MutableMap> = HashMap() + val body: MutableMap> = HashMap() val errors = ex.bindingResult .fieldErrors - .stream() - .map { obj: FieldError -> obj.defaultMessage } - .collect(Collectors.toList()) + .associate { obj: FieldError -> obj.field to obj.defaultMessage } body["errors"] = errors