Skip to content

Commit

Permalink
fix: 예외 처리 방식 및 메시지 수정 (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonyj1022 authored and apptie committed Oct 7, 2023
1 parent 274b2b0 commit 43e205a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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 @@ -15,19 +16,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 = "카테고리 아이디는 음수 또는 0을 입력할 수 없습니다.")
@Positive(message = "잘못된 카테고리 입니다.")
Long subCategoryId,

List<Long> thirdRegionIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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 @@ -42,7 +41,6 @@
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 @@ -97,7 +95,7 @@ public ResponseEntity<ExceptionResponse> handleMessageNotFoundException(final Me

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

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

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

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

0 comments on commit 43e205a

Please sign in to comment.