Skip to content

Commit

Permalink
Revert "fix: 예외 처리 방식 및 메시지 수정 (#465)"
Browse files Browse the repository at this point in the history
This reverts commit 2e2fed2.
  • Loading branch information
swonny authored Oct 6, 2023
1 parent 7fd2d87 commit 4f2949d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;

import java.time.LocalDateTime;
import java.util.List;

Expand All @@ -16,19 +15,19 @@ public record CreateAuctionRequest(
String description,

@NotNull(message = "입찰 단위가 입력되지 않았습니다.")
@Positive(message = "금액은 양수로 입력해주세요.")
@Positive(message = "금액은 음수를 입력할 수 없습니다.")
Integer bidUnit,

@NotNull(message = "시작가가 입력되지 않았습니다.")
@Positive(message = "금액은 양수로 입력해주세요.")
@Positive(message = "금액은 음수를 입력할 수 없습니다.")
Integer startPrice,

@NotNull(message = "마감 시간이 입력되지 않았습니다.")
@FutureOrPresent(message = "마감 시간은 과거를 입력할 수 없습니다.")
LocalDateTime closingTime,

@NotNull(message = "하위 카테고리가 입력되지 않았습니다.")
@Positive(message = "잘못된 카테고리 입니다.")
@Positive(message = "카테고리 아이디는 음수 또는 0을 입력할 수 없습니다.")
Long subCategoryId,

List<Long> thirdRegionIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.ddang.ddang.report.application.exception.InvalidReportAuctionException;
import com.ddang.ddang.report.application.exception.InvalidReporterToAuctionException;
import com.ddang.ddang.user.application.exception.UserNotFoundException;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
Expand All @@ -41,6 +42,7 @@
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import java.net.MalformedURLException;
import java.util.stream.Collectors;

@RestControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
Expand Down Expand Up @@ -95,7 +97,7 @@ public ResponseEntity<ExceptionResponse> handleMessageNotFoundException(final Me

@ExceptionHandler(UnableToChatException.class)
public ResponseEntity<ExceptionResponse> handleUnableToChatException(final UnableToChatException ex) {
logger.warn(String.format(EXCEPTION_FORMAT, UnableToChatException.class), ex);
logger.warn(String.format(EXCEPTION_FORMAT, MessageNotFoundException.class), ex);

return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new ExceptionResponse(ex.getMessage()));
Expand Down Expand Up @@ -334,7 +336,10 @@ protected ResponseEntity<Object> handleMethodArgumentNotValid(
) {
logger.info(String.format(EXCEPTION_FORMAT, MethodArgumentNotValidException.class), ex);

final String message = ex.getFieldErrors().get(0).getDefaultMessage();
final String message = ex.getFieldErrors()
.stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.joining(System.lineSeparator()));

return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new ExceptionResponse(message));
Expand Down

0 comments on commit 4f2949d

Please sign in to comment.