Skip to content

Commit

Permalink
#511 [feat] 에러코드 요청에 따른 수정
Browse files Browse the repository at this point in the history
#511 [feat] 에러코드 요청에 따른 수정
  • Loading branch information
sohyundoh authored Sep 9, 2024
2 parents 56e4b39 + 1bb7042 commit 563f8b6
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.BadRequestException;
import com.mile.common.utils.SecureUrlUtil;
import com.mile.exception.model.NotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
Expand Down Expand Up @@ -36,7 +37,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
try {
return secureUrlUtil.decodeUrl(id);
} catch (NumberFormatException e) {
throw new BadRequestException(ErrorMessage.INVALID_URL_EXCEPTION);
throw new NotFoundException(ErrorMessage.INVALID_URL_EXCEPTION);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.BadRequestException;
import com.mile.common.utils.SecureUrlUtil;
import com.mile.exception.model.NotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
Expand Down Expand Up @@ -36,7 +37,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
try {
return secureUrlUtil.decodeUrl(moimId);
} catch (NumberFormatException e) {
throw new BadRequestException(ErrorMessage.INVALID_URL_EXCEPTION);
throw new NotFoundException(ErrorMessage.INVALID_URL_EXCEPTION);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.BadRequestException;
import com.mile.common.utils.SecureUrlUtil;
import com.mile.exception.model.NotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
Expand Down Expand Up @@ -35,7 +36,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
try {
return secureUrlUtil.decodeUrl(postId);
} catch (NumberFormatException e) {
throw new BadRequestException(ErrorMessage.INVALID_URL_EXCEPTION);
throw new NotFoundException(ErrorMessage.INVALID_URL_EXCEPTION);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.BadRequestException;
import com.mile.common.utils.SecureUrlUtil;
import com.mile.exception.model.NotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
Expand Down Expand Up @@ -36,7 +37,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
try {
return secureUrlUtil.decodeUrl(replyId);
} catch (NumberFormatException e) {
throw new BadRequestException(ErrorMessage.INVALID_URL_EXCEPTION);
throw new NotFoundException(ErrorMessage.INVALID_URL_EXCEPTION);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.BadRequestException;
import com.mile.common.utils.SecureUrlUtil;
import com.mile.exception.model.NotFoundException;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.core.MethodParameter;
Expand Down Expand Up @@ -36,7 +37,7 @@ public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer m
try {
return secureUrlUtil.decodeUrl(topicId);
} catch (NumberFormatException e) {
throw new BadRequestException(ErrorMessage.INVALID_URL_EXCEPTION);
throw new NotFoundException(ErrorMessage.INVALID_URL_EXCEPTION);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class MoimControllerTest {
private static final String AUTHORIZATION = "Authorization";
private static final int OK = 200;
private static final int CREATED = 201;
private static final int BAD_REQUEST = 400;
private static final int NOT_FOUND = 404;
private static Long USER_ID;
private static String MOIM_ID;
private static String randomString;
Expand Down Expand Up @@ -132,7 +132,7 @@ public void parameterErrorTest() throws Exception {
).andDo(print()).andReturn();

//then
assertThat(result.getResponse().getStatus()).isEqualTo(BAD_REQUEST);
assertThat(result.getResponse().getStatus()).isEqualTo(NOT_FOUND);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ public enum ErrorMessage {
HANDLER_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "요청하신 URL은 정보가 없습니다."),
COMMENT_NOT_FOUND(40406, "해당 댓글이 존재하지 않습니다."),
CURIOUS_NOT_FOUND(40407, "해당 궁금해요는 존재하지 않습니다."),
TOPIC_NOT_FOUND(40408, "해당 글감이 존재하지 않습니다."),
KEYWORD_NOT_FOUND(40409, "해당 글모임의 글감 키워드가 존재하지 않습니다."),
WRITER_NOT_FOUND(40411, "해당 작가는 존재하지 않습니다."),
TOPIC_NOT_FOUND(40408, "글감이 존재하지 않습니다."),
RECOMMEND_NOT_FOUND(40412, "추천 글감을 받아오는데 실패했습니다."),
MOIM_TOPIC_NOT_FOUND(40413, "해당 모임의 글감이 존재하지 않습니다."),
REPLY_NOT_FOUND(40416, "Id에 해당하는 대댓글이 없습니다."),
INVALID_URL_EXCEPTION(40413, "해당 URI는 자원을 표시할 수 없습니다."),
/*
Bad Request
*/
Expand All @@ -38,11 +35,9 @@ public enum ErrorMessage {
BEARER_LOST_ERROR(HttpStatus.BAD_REQUEST.value(), "토큰의 요청에 Bearer이 담겨 있지 않습니다."),
POST_NOT_TEMPORARY_ERROR(40008, "해당 글은 임시저장 글이 아닙니다."),
POST_TEMPORARY_ERROR(HttpStatus.BAD_REQUEST.value(), "해당 글은 임시저장글입니다."),
PATH_PARAMETER_INVALID_ERROR(40010, "해당 URI는 자원을 표시할 수 없습니다."),
REQUEST_URL_WRONG_ERROR(HttpStatus.BAD_REQUEST.value(), "요청 URL를 다시 확인해주세요"),
IMAGE_EXTENSION_INVALID_ERROR(HttpStatus.BAD_REQUEST.value(), "이미지 확장자는 jpg, png, webp만 가능합니다."),
IMAGE_SIZE_INVALID_ERROR(HttpStatus.BAD_REQUEST.value(), "이미지 사이즈는 5MB를 넘을 수 없습니다."),
INVALID_URL_EXCEPTION(40014, "해당 URI는 자원을 표시할 수 없습니다."),
LEAST_TOPIC_SIZE_OF_MOIM_ERROR(40015, "모임에는 최소 하나의 글감이 있어야 합니다."),
USER_MOIM_ALREADY_JOIN(40016, "사용자는 이미 모임에 가입했습니다."),
WRITER_NAME_LENGTH_WRONG(40017, "사용 불가능한 필명입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public CommentReply findById(
final Long replyId
) {
return commentReplyRepository.findById(replyId).orElseThrow(
() -> new NotFoundException(ErrorMessage.REPLY_NOT_FOUND)
() -> new NotFoundException(ErrorMessage.COMMENT_NOT_FOUND)
);
}

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

import com.mile.exception.message.ErrorMessage;
import com.mile.exception.model.BadRequestException;
import com.mile.exception.model.NotFoundException;
import org.springframework.stereotype.Component;

import java.util.Base64;
Expand All @@ -17,7 +18,7 @@ public Long decodeUrl(final String url) {
try {
return Long.parseLong(new String(Base64.getUrlDecoder().decode(url)));
} catch (IllegalArgumentException e) {
throw new BadRequestException(ErrorMessage.PATH_PARAMETER_INVALID_ERROR);
throw new NotFoundException(ErrorMessage.INVALID_URL_EXCEPTION);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void checkTopicListEmpty(
final List<Topic> topicList
) {
if (topicList.isEmpty()) {
throw new NotFoundException(ErrorMessage.KEYWORD_NOT_FOUND);
throw new NotFoundException(ErrorMessage.TOPIC_NOT_FOUND);
}
}

Expand Down Expand Up @@ -186,7 +186,7 @@ public String findLatestTopicByMoim(
) {
return topicRepository.findLatestTopicByMoim(moim)
.orElseThrow(
() -> new NotFoundException(ErrorMessage.MOIM_TOPIC_NOT_FOUND)
() -> new NotFoundException(ErrorMessage.TOPIC_NOT_FOUND)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public List<WriterName> findByWriter(final User user) {

public WriterName findById(final Long id) {
return writerNameRepository.findById(id).orElseThrow(
() -> new NotFoundException(ErrorMessage.WRITER_NOT_FOUND)
() -> new NotFoundException(ErrorMessage.USER_NOT_FOUND)
);
}

Expand Down

0 comments on commit 563f8b6

Please sign in to comment.