Skip to content

Commit

Permalink
refactor: 에러 메시지 ENUM 정의 #56
Browse files Browse the repository at this point in the history
  • Loading branch information
mungsil committed Nov 10, 2024
1 parent d7ef3a0 commit 0aafdfd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.munecting.api.domain.user.dao.UserRepository;
import com.munecting.api.domain.user.entity.User;
import com.munecting.api.global.common.dto.response.Status;
import com.munecting.api.global.error.exception.InternalServerException;
import com.munecting.api.global.error.exception.InvalidValueException;
import lombok.RequiredArgsConstructor;
Expand All @@ -12,6 +11,8 @@

import java.util.Random;

import static com.munecting.api.global.common.dto.response.Status.*;

@Service
@Slf4j
@RequiredArgsConstructor
Expand All @@ -23,9 +24,6 @@ public class UserNicknameService {
private static final int MAX_LENGTH = 15;

private static final String NAME_VALUE_RULES = "^(?=.*[a-zA-Z0-9가-힣])[a-zA-Z가-힣][a-zA-Z0-9가-힣_]*$";
private static final String NICKNAME_LENGTH_ERROR_MESSAGE = "닉네임은 2-15자 사이여야 합니다.";
private static final String NICKNAME_WRONG_VALUE_ERROR_MESSAGE = "닉네임은 한글, 영문, 숫자, 언더바(_)만 사용 가능하며, 첫 글자는 언더바 또는 숫자일 수 없습니다.";
private static final String NICKNAME_DUPLICATED_ERROR_MESSAGE = "이미 사용 중인 닉네임입니다.";

private static final String DEFAULT_NICKNAME = "뮤넥터";
private static final String DELIMITER = "_";
Expand All @@ -45,15 +43,15 @@ public String updateNickname(User user, String nickname) {

private void validateNickname(User existingUser, String nickname) {
if (isInvalidNicknameLength(nickname)) {
throw new InvalidValueException(Status.BAD_REQUEST, NICKNAME_LENGTH_ERROR_MESSAGE);
throw new InvalidValueException(INVALID_NICKNAME_LENGTH);
}

if (isInvalidNamingRule(nickname)) {
throw new InvalidValueException(Status.BAD_REQUEST, NICKNAME_WRONG_VALUE_ERROR_MESSAGE);
throw new InvalidValueException(INVALID_NICKNAME_VALUE);
}

if (isDuplicatedNickname(existingUser, nickname)) {
throw new InvalidValueException(Status.CONFLICT, NICKNAME_DUPLICATED_ERROR_MESSAGE);
throw new InvalidValueException(DUPLICATED_NICKNAME);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public enum Status {

// User 오류 응답
USER_NOT_FOUND(HttpStatus.NOT_FOUND, "USER404", "존재하지 않는 회원입니다."),
INVALID_NICKNAME_LENGTH(HttpStatus.BAD_REQUEST, "USER_NICKNAME400", "닉네임은 2-15자 사이여야 합니다."),
INVALID_NICKNAME_VALUE(HttpStatus.BAD_REQUEST, "USER_NICKNAME400", "닉네임은 한글, 영문, 숫자, 언더바(_)만 사용 가능하며, 첫 글자는 언더바 또는 숫자일 수 없습니다."),
DUPLICATED_NICKNAME(HttpStatus.CONFLICT, "USER_NICKNAME409","이미 사용 중인 닉네임입니다."),

// 분산락 오류 응답
DISTRIBUTED_LOCK_ACQUISITION_FAILURE(HttpStatus.CONFLICT, "LOCK409", "잠시 후에 시도해주세요."),
Expand Down

0 comments on commit 0aafdfd

Please sign in to comment.