Skip to content

Commit

Permalink
fix: Fix the dataErrors ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz.gryzbon committed Apr 27, 2022
1 parent a3ff96c commit e5adb1f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -16,6 +11,11 @@
"name" : "message",
"value" : "b",
"message" : "validation.wrongSize"
}, {
"code" : "Min",
"name" : "number",
"value" : "3",
"message" : "validation.lessThanAcceptedMinimum"
} ],
"attributes" : {
"traceId" : "40e1488ed0001adc",
Expand Down

0 comments on commit e5adb1f

Please sign in to comment.