Skip to content

Commit

Permalink
Merge pull request #34 from Seasoning-Today/refactor/#24-validate-htt…
Browse files Browse the repository at this point in the history
…p-status-code

HTTP 상태 코드 중간 점검
  • Loading branch information
csct3434 authored Jan 27, 2024
2 parents 47ad901 + 9cc72ce commit d017749
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void cancelLike(Long userId, Long articleId) {
validatePermission(userId, article);

ArticleLike articleLike = articleLikeRepository.findByArticleAndUser(articleId, userId)
.orElseThrow(() -> new CustomException(HttpStatus.FORBIDDEN, "좋아요를 누르지 않았습니다"));
.orElseThrow(() -> new CustomException(HttpStatus.BAD_REQUEST, "좋아요를 누르지 않았습니다"));

articleLikeRepository.delete(articleLike);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void validateRequest(RegisterArticleCommand command) {
}

if (command.getImages().size() > ARTICLE_IMAGES_LIMIT) {
throw new CustomException(HttpStatus.FORBIDDEN, "이미지 개수 초과");
throw new CustomException(HttpStatus.BAD_REQUEST, "이미지 개수 초과");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private void validateRequest(Article article, UpdateArticleCommand command) {
}

if (command.getImages().size() > ARTICLE_IMAGES_LIMIT) {
throw new CustomException(HttpStatus.FORBIDDEN, "이미지 개수 초과");
throw new CustomException(HttpStatus.BAD_REQUEST, "이미지 개수 초과");
}

Long authorId = article.getUser().getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private String resolveTokenFromAuthorizationHeader(HttpServletRequest request) {

private UserPrincipal createPrincipal(String token) {
User user = userRepository.findById(JwtUtil.getUserId(token))
.orElseThrow(() -> new CustomException(HttpStatus.NOT_FOUND, "회원 조회 실패"));
.orElseThrow(() -> new CustomException(HttpStatus.UNAUTHORIZED, "Invalid Token Claims"));

return UserPrincipal.build(user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private void selfValidate() {
String regex = "^(?!.*\\.\\.)(?!.*\\.$)[^\\W][\\w.]{4,19}$";

if (accountId == null || accountId.matches(upperCases) || !accountId.matches(regex)) {
throw new CustomException(HttpStatus.FORBIDDEN, "Invalid ID Format");
throw new CustomException(HttpStatus.BAD_REQUEST, "Invalid ID Format");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private void selfValidate() {
String regex = "^[a-zA-Z0-9가-힣]{2,10}$";

if (nickname == null || !Pattern.matches(regex, nickname)) {
throw new CustomException(HttpStatus.FORBIDDEN, "Invalid Nickname");
throw new CustomException(HttpStatus.BAD_REQUEST, "Invalid Nickname");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public void failedByInvalidCharacter(String accountId) {
private void assertFailedValidation(String invalidAccountId) {
assertThatThrownBy(() -> new AccountId(invalidAccountId))
.isInstanceOf(CustomException.class)
.hasFieldOrPropertyWithValue("httpStatus", HttpStatus.FORBIDDEN);
.hasFieldOrPropertyWithValue("httpStatus", HttpStatus.BAD_REQUEST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public void failedByInvalidCharacter(String nickname) {
private void assertFailedValidation(String invalidNickname) {
assertThatThrownBy(() -> new Nickname(invalidNickname))
.isInstanceOf(CustomException.class)
.hasFieldOrPropertyWithValue("httpStatus", HttpStatus.FORBIDDEN);
.hasFieldOrPropertyWithValue("httpStatus", HttpStatus.BAD_REQUEST);
}
}

0 comments on commit d017749

Please sign in to comment.