Skip to content

Commit

Permalink
feat: IllegalArgument -> BadRequest 로 통일
Browse files Browse the repository at this point in the history
  • Loading branch information
songyi00 committed Nov 15, 2024
1 parent e59e59f commit bae5dde
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nexters.goalpanzi.domain.mission;

import com.nexters.goalpanzi.exception.BadRequestException;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AccessLevel;
Expand Down Expand Up @@ -44,7 +45,7 @@ private static String generateRandomCode() {

private void validate() {
if (!StringUtils.hasText(code) || this.code.length() != CODE_LENGTH) {
throw new IllegalArgumentException(INVALID_INVITATION_CODE.getMessage());
throw new BadRequestException(INVALID_INVITATION_CODE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.nexters.goalpanzi.domain.common.BaseEntity;
import com.nexters.goalpanzi.domain.member.Member;
import com.nexters.goalpanzi.exception.BadRequestException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
Expand Down Expand Up @@ -62,7 +63,7 @@ public MissionMember(final Member member, final Mission mission, final Integer v

public static MissionMember join(final Member member, final Mission mission) {
if (mission.isMissionPeriod()) {
throw new IllegalArgumentException(CAN_NOT_JOIN_MISSION.toString());
throw new BadRequestException(CAN_NOT_JOIN_MISSION);
}
return new MissionMember(member, mission, 0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nexters.goalpanzi.domain.mission;

import com.nexters.goalpanzi.exception.BadRequestException;
import com.nexters.goalpanzi.exception.BaseException;
import lombok.Getter;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -61,6 +63,6 @@ public static MissionStatus fromMission(
return COMPLETED;
}

throw new IllegalArgumentException(UNKNOWN_MISSION.getMessage(mission, missionMember));
throw new BaseException(UNKNOWN_MISSION, mission.getId(), missionMember.getMember().getId());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.nexters.goalpanzi.domain.mission;

import com.nexters.goalpanzi.exception.BadRequestException;
import lombok.Getter;

import java.util.Arrays;
Expand All @@ -25,6 +26,6 @@ public static TimeOfDay of(final String startTime, final String endTime) {
return Arrays.stream(TimeOfDay.values())
.filter(timeOfDay -> timeOfDay.startTime.equals(startTime) && timeOfDay.endTime.equals(endTime))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException(INVALID_UPLOAD_TIME_OF_DAY.getMessage()));
.orElseThrow(() -> new BadRequestException(INVALID_UPLOAD_TIME_OF_DAY));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum ErrorCode {
INVALID_INVITATION_CODE("초대코드가 올바르지 않습니다."),
INVALID_UPLOAD_TIME_OF_DAY("올바르지 않은 미션 인증 업로드 시간대입니다."),
CANNOT_DELETE_MISSION("미션 삭제 권한이 없습니다."),
UNKNOWN_MISSION("정의되지 않은 미션상태입니다."),
UNKNOWN_MISSION("정의되지 않은 미션상태입니다. [missionId=%s, memberId=%s]"),

// MISSION MEMBER
ALREADY_EXISTS_MISSION_MEMBER("이미 참여한 미션입니다. [%s]"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,22 @@ public ResponseEntity<ErrorResponse> handleUnauthorizedException(final Unauthori
.body(new ErrorResponse(HttpStatus.UNAUTHORIZED.value(), exception.getMessage(), exception.getErrorCode()));
}

@ExceptionHandler({BadRequestException.class, IllegalArgumentException.class})
public ResponseEntity<ErrorResponse> handleBadRequestException(final RuntimeException exception) {
@ExceptionHandler({IllegalArgumentException.class})
public ResponseEntity<ErrorResponse> handleIllegalArgumentException(final IllegalArgumentException exception) {
logger.error("message", exception);

return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), exception.getMessage(), ErrorCode.BAD_REQUEST));
}

@ExceptionHandler({BadRequestException.class})
public ResponseEntity<ErrorResponse> handleBadRequestException(final BadRequestException exception) {
logger.error("message", exception);

return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(new ErrorResponse(HttpStatus.BAD_REQUEST.value(), exception.getMessage(), exception.getErrorCode()));
}

@ExceptionHandler({NoSuchElementException.class})
public ResponseEntity<ErrorResponse> handleNoSuchElementException(final RuntimeException exception) {
logger.error("message", exception);
Expand Down

0 comments on commit bae5dde

Please sign in to comment.