From e5adb1f749a228e26dcffcadd3200034eb46149f Mon Sep 17 00:00:00 2001 From: "lukasz.gryzbon" Date: Wed, 27 Apr 2022 23:51:21 +0100 Subject: [PATCH] fix: Fix the dataErrors ordering --- .../server/config/ControllerExceptionHandler.kt | 2 +- .../config/CustomResponseEntityExceptionHandler.kt | 2 +- ...Exception_MultiplePropertyInvalidData.approved.json | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/server/src/main/kotlin/com/lsdconsulting/exceptionhandling/server/config/ControllerExceptionHandler.kt b/server/src/main/kotlin/com/lsdconsulting/exceptionhandling/server/config/ControllerExceptionHandler.kt index e7a23e0..21e7d2e 100644 --- a/server/src/main/kotlin/com/lsdconsulting/exceptionhandling/server/config/ControllerExceptionHandler.kt +++ b/server/src/main/kotlin/com/lsdconsulting/exceptionhandling/server/config/ControllerExceptionHandler.kt @@ -58,7 +58,7 @@ class ControllerExceptionHandler( private fun handle(ex: ConstraintViolationException, request: WebRequest): ResponseEntity<*> { val bodyDataErrors = ex.constraintViolations .map { constraintViolation: ConstraintViolation<*> -> convert(constraintViolation) } - .sortedBy { it.code } + .sortedBy { it.name + it.value + it.code } val errorResponse = ErrorResponse( errorCode = PARAMETER_VALIDATION_FAILED_ERROR_CODE, messages = listOf(VALIDATION_FAILED), diff --git a/server/src/main/kotlin/com/lsdconsulting/exceptionhandling/server/config/CustomResponseEntityExceptionHandler.kt b/server/src/main/kotlin/com/lsdconsulting/exceptionhandling/server/config/CustomResponseEntityExceptionHandler.kt index fcb2ae9..c6b8608 100644 --- a/server/src/main/kotlin/com/lsdconsulting/exceptionhandling/server/config/CustomResponseEntityExceptionHandler.kt +++ b/server/src/main/kotlin/com/lsdconsulting/exceptionhandling/server/config/CustomResponseEntityExceptionHandler.kt @@ -141,7 +141,7 @@ class CustomResponseEntityExceptionHandler( .fieldErrors .stream() .map { fieldError: FieldError -> convert(fieldError) } - .sorted(Comparator.comparing { obj: DataError -> obj.code!! }) + .sorted(Comparator.comparing { obj: DataError -> obj.name + obj.value + obj.code!! }) .collect(Collectors.toList()) } diff --git a/server/src/test/resources/data/com/lsdconsulting/exceptionhandling/server/integration/validation/DataValidationIntegrationShould.return400ForMethodArgumentNotValidException_MultiplePropertyInvalidData.approved.json b/server/src/test/resources/data/com/lsdconsulting/exceptionhandling/server/integration/validation/DataValidationIntegrationShould.return400ForMethodArgumentNotValidException_MultiplePropertyInvalidData.approved.json index 92bdb37..ad41b34 100644 --- a/server/src/test/resources/data/com/lsdconsulting/exceptionhandling/server/integration/validation/DataValidationIntegrationShould.return400ForMethodArgumentNotValidException_MultiplePropertyInvalidData.approved.json +++ b/server/src/test/resources/data/com/lsdconsulting/exceptionhandling/server/integration/validation/DataValidationIntegrationShould.return400ForMethodArgumentNotValidException_MultiplePropertyInvalidData.approved.json @@ -2,11 +2,6 @@ "errorCode" : "INVALID", "messages" : [ "Validation failed" ], "dataErrors" : [ { - "code" : "Min", - "name" : "number", - "value" : "3", - "message" : "validation.lessThanAcceptedMinimum" - }, { "code" : "Pattern", "name" : "message", "value" : "b", @@ -16,6 +11,11 @@ "name" : "message", "value" : "b", "message" : "validation.wrongSize" + }, { + "code" : "Min", + "name" : "number", + "value" : "3", + "message" : "validation.lessThanAcceptedMinimum" } ], "attributes" : { "traceId" : "40e1488ed0001adc",