Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

예외 처리 방식 및 메시지 수정 #465

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading