diff --git a/src/main/java/com/haejwo/tripcometrue/global/exception/GlobalExceptionRestAdvice.java b/src/main/java/com/haejwo/tripcometrue/global/exception/GlobalExceptionRestAdvice.java index 6a81734f..2e02c309 100644 --- a/src/main/java/com/haejwo/tripcometrue/global/exception/GlobalExceptionRestAdvice.java +++ b/src/main/java/com/haejwo/tripcometrue/global/exception/GlobalExceptionRestAdvice.java @@ -1,7 +1,7 @@ package com.haejwo.tripcometrue.global.exception; import com.haejwo.tripcometrue.global.util.ResponseDTO; -import java.util.Map; +import java.util.List; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.dao.DataAccessException; @@ -9,7 +9,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.validation.BindException; import org.springframework.validation.BindingResult; -import org.springframework.validation.FieldError; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; @@ -66,14 +65,16 @@ public ResponseEntity> handleValidationExceptions( BindingResult bindingResult = e.getBindingResult(); - Map fieldErrors = bindingResult.getFieldErrors() + List fieldErrors = bindingResult.getFieldErrors() .stream() - .collect(Collectors.toMap(FieldError::getField, FieldError::getDefaultMessage)); + .map(error -> error.getField() + ": " + error.getDefaultMessage()) + .collect(Collectors.toList()); log.error(e.getMessage(), e); + String errorMessage = String.join(", ", fieldErrors); + return ResponseEntity .status(HttpStatus.BAD_REQUEST) - .body(ResponseDTO.errorWithMessage(HttpStatus.BAD_REQUEST, - fieldErrors.values().toString().substring(1,fieldErrors.values().toString().length()-1))); + .body(ResponseDTO.errorWithMessage(HttpStatus.BAD_REQUEST, errorMessage)); } }