Change errors formatter with field: error format
This commit is contained in:
parent
640d1313f9
commit
3fb4c227d6
1 changed files with 2 additions and 4 deletions
|
@ -16,13 +16,11 @@ import java.util.stream.Collectors
|
|||
class GlobalExceptionHandler : ResponseEntityExceptionHandler() {
|
||||
|
||||
override fun handleMethodArgumentNotValid(ex: MethodArgumentNotValidException, headers: HttpHeaders, status: HttpStatusCode, request: WebRequest): ResponseEntity<Any>? {
|
||||
val body: MutableMap<String, List<String?>> = HashMap()
|
||||
val body: MutableMap<String, Map<String, String?>> = 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
|
||||
|
||||
|
|
Loading…
Reference in a new issue