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

[BugFix/BE] 액세스 토큰 요청 시 에러코드를 수정하고 에러코드 방식을 수정한다. #750

Merged
merged 4 commits into from
Oct 14, 2022
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
24 changes: 4 additions & 20 deletions backend/src/docs/asciidoc/auth.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,16 @@

=== 로그인

==== 발생 가능 에러

- 40002, 40060, 50000, 50001

operation::auth-login[snippets='http-request,http-response']
operation::auth-login[snippets='error-code-table,http-request,http-response']

=== 어드민 로그인

==== 발생 가능 에러

- 40300, 40410, 50000, 50001

operation::auth-admin-login[snippets='http-request,http-response']
operation::auth-admin-login[snippets='error-code-table,http-request,http-response']

=== 액세스 토큰 발급

==== 발생 가능 에러

- 40002, 40104, 40105, 50000, 50001

operation::auth-issue-access-token[snippets='http-request,http-response']
operation::auth-issue-access-token[snippets='error-code-table,http-request,http-response']

=== 로그아웃

==== 발생 가능 에러

- 40105

operation::auth-logout[snippets='http-request,http-response']
operation::auth-logout[snippets='error-code-table,http-request,http-response']
18 changes: 3 additions & 15 deletions backend/src/docs/asciidoc/inventoryProducts.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,12 @@

=== 나의 로그인 정보로 인벤토리를 조회

==== 발생 가능 에러

- 40100, 40101, 40102

operation::inventoryProducts-get-own[snippets='http-request,http-response']
operation::inventoryProducts-get-own[snippets='error-code-table,http-request,http-response']

=== 멤버 아이디로 인벤토리를 조회

==== 발생 가능 에러

- 40440

operation::inventoryProducts-get-by-memberId[snippets='http-request,http-response']
operation::inventoryProducts-get-by-memberId[snippets='error-code-table,http-request,http-response']

=== 나의 대표 장비 수정

==== 발생 가능 에러

- 40040, 40041, 40042, 40043

operation::inventoryProducts-update[snippets='http-request,http-response']
operation::inventoryProducts-update[snippets='error-code-table,http-request,http-response']
42 changes: 7 additions & 35 deletions backend/src/docs/asciidoc/members.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,19 @@

=== 로그인된 상태로 나의 회원 정보 조회

==== 발생 가능 에러

- 40100, 40101, 40102

operation::members-get-own[snippets='http-request,http-response']
operation::members-get-own[snippets='error-code-table,http-request,http-response']

=== 회원 정보 조회

==== 부가 조건
- 로그인 시 회원 정보를 조회하려면 헤더에 토큰 정보가 필요
`Authorization: Bearer Token`

==== 발생 가능 에러

- 40410

operation::members-get-by-memberId[snippets='http-request,http-response']
operation::members-get-by-memberId[snippets='error-code-table,http-request,http-response']

=== 로그인된 상태로 나의 회원 정보 수정

==== 발생 가능 에러

- 40010, 40011, 40100, 40101, 40102

operation::members-update[snippets='http-request,http-response']
operation::members-update[snippets='error-code-table,http-request,http-response']

=== 회원 검색

Expand Down Expand Up @@ -60,27 +48,15 @@ operation::members-update[snippets='http-request,http-response']
- 로그인 시 회원 정보를 조회하려면 헤더에 토큰 정보가 필요
`Authorization: Bearer Token`

==== 발생 가능 에러

- 40000, 40001

operation::members-search[snippets='http-request,http-response']
operation::members-search[snippets='error-code-table,http-request,http-response']

=== 다른 회원 팔로우

==== 발생 가능 에러

- 40050, 40051, 40060, 40410

operation::follow[snippets='http-request,http-response']
operation::follow[snippets='error-code-table,http-request,http-response']

=== 다른 회원 언팔로우

==== 발생 가능 에러

- 40052, 40053, 40410

operation::unfollow[snippets='http-request,http-response']
operation::unfollow[snippets='error-code-table,http-request,http-response']

=== 팔로우하는 회원 검색

Expand Down Expand Up @@ -109,8 +85,4 @@ operation::unfollow[snippets='http-request,http-response']
- `followerCount,desc`(팔로워 수 순)
- 없을 경우 등록 순서

==== 발생 가능 에러

- 40100, 40101, 40102

operation::search-followings[snippets='http-request,http-response']
operation::search-followings[snippets='error-code-table,http-request,http-response']
36 changes: 6 additions & 30 deletions backend/src/docs/asciidoc/products.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,10 @@

=== 제품 단일 제품 조회

==== 발생 가능 에러

- 40420

operation::products-get[snippets='http-request,http-response']
operation::products-get[snippets='error-code-table,http-request,http-response']

=== 제품 목록 페이지 조회

==== 발생 가능 에러

- 40000, 40001

==== 검색 조건

- 제품 이름을 query로 하여 검색
Expand All @@ -35,36 +27,20 @@ operation::products-get[snippets='http-request,http-response']
- `reviewCount,desc`(리뷰 많은순)
- 없을 경우 등록 순서

operation::products-page-get[snippets='http-request,http-response']
operation::products-page-get[snippets='error-code-table,http-request,http-response']

=== 특정 제품의 사용자 통계를 조회

==== 발생 가능 에러

- 40420

operation::products-member-statistics-get[snippets='http-request,http-response']
operation::products-member-statistics-get[snippets='error-code-table,http-request,http-response']

=== 제품 추가(어드민)

==== 발생 가능 에러

- 40003, 40100, 40101, 40102, 40300

operation::admin-products-create[snippets='http-request,http-response']
operation::admin-products-create[snippets='error-code-table,http-request,http-response']

=== 제품 수정(어드민)

==== 발생 가능 에러

- 40003, 40100, 40101, 40102, 40300

operation::admin-products-update[snippets='http-request,http-response']
operation::admin-products-update[snippets='error-code-table,http-request,http-response']

=== 제품 삭제(어드민)

==== 발생 가능 에러

- 40100, 40101, 40102, 40300, 40420

operation::admin-products-delete[snippets='http-request,http-response']
operation::admin-products-delete[snippets='error-code-table,http-request,http-response']
38 changes: 8 additions & 30 deletions backend/src/docs/asciidoc/reviews.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,25 @@

=== 리뷰 작성

==== 발생 가능 에러

- 40030, 40031, 40032, 40033, 40060, 40100, 40101, 40102, 40103

operation::reviews-create[snippets='http-request,http-response']
operation::reviews-create[snippets='error-code-table,http-request,http-response']

=== 특정 제품의 리뷰 목록 페이지 조회

==== 발생 가능 에러

- 40001, 40430

==== sort 조건

- `createdAt,desc`(최신순)
- `rating,desc`(평점순)

operation::reviews-by-product-page-get[snippets='http-request,http-response']
operation::reviews-by-product-page-get[snippets='error-code-table,http-request,http-response']

=== 모든 리뷰 목록 페이지 조회

==== 발생 가능 에러

- 40001

==== sort 조건

- `createdAt,desc`(최신순)
- `rating,desc`(평점순)

operation::reviews-page-get[snippets='http-request,http-response']

operation::reviews-page-get[snippets='error-code-table,http-request,http-response']

=== 내가 작성한 리뷰 목록 페이지 조회

Expand All @@ -44,7 +30,7 @@ operation::reviews-page-get[snippets='http-request,http-response']
- `createdAt,desc`(최신순)
- `rating,desc`(평점순)

operation::reviews-page-get-own[snippets='http-request,http-response']
operation::reviews-page-get-own[snippets='error-code-table,http-request,http-response']

=== 회원의 아이디로 리뷰 목록 페이지 조회

Expand All @@ -53,24 +39,16 @@ operation::reviews-page-get-own[snippets='http-request,http-response']
- `createdAt,desc`(최신순)
- `rating,desc`(평점순)

operation::reviews-page-get-by-memberId[snippets='http-request,http-response']
operation::reviews-page-get-by-memberId[snippets='error-code-table,http-request,http-response']

=== 인벤토리 아이디로 리뷰 조회

operation::reviews-get-by-inventoryProductId[snippets='http-request,http-response']
operation::reviews-get-by-inventoryProductId[snippets='error-code-table,http-request,http-response']

=== 리뷰 수정

==== 발생 가능 에러

- 40100, 40101, 40102, 40300, 40410, 40430

operation::reviews-update[snippets='http-request,http-response']
operation::reviews-update[snippets='error-code-table,http-request,http-response']

=== 리뷰 삭제

==== 발생 가능 에러

- 40100, 40101, 40102, 40300, 40410, 40430

operation::reviews-delete[snippets='http-request,http-response']
operation::reviews-delete[snippets='error-code-table,http-request,http-response']
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.woowacourse.f12.exception.forbidden.NotAdminException;
import com.woowacourse.f12.exception.notfound.MemberNotFoundException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenExpiredException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenInvalidException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenNotFoundException;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -85,7 +85,7 @@ private Member addOrUpdateMember(final GitHubProfileResponse gitHubProfileRespon

public IssuedTokensResponse issueAccessToken(final String refreshTokenValue) {
final RefreshToken refreshToken = refreshTokenRepository.findToken(refreshTokenValue)
.orElseThrow(RefreshTokenInvalidException::new);
.orElseThrow(RefreshTokenNotFoundException::new);
checkExpired(refreshTokenValue, refreshToken);
final Long memberId = refreshToken.getMemberId();
final Role memberRole = memberRepository.findById(memberId)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.woowacourse.f12.exception.unauthorized;

import com.woowacourse.f12.exception.ErrorCode;

public class RefreshTokenNotFoundException extends UnauthorizedException {

public RefreshTokenNotFoundException() {
super(ErrorCode.REFRESH_TOKEN_NOT_FOUND, "서버에 존재하지 않는 리프레시 토큰입니다.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import com.woowacourse.f12.exception.internalserver.ExternalServerException;
import com.woowacourse.f12.exception.internalserver.InternalServerException;
import com.woowacourse.f12.exception.notfound.NotFoundException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenInvalidException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenExpiredException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenNotFoundException;
import com.woowacourse.f12.exception.unauthorized.UnauthorizedException;
import com.woowacourse.f12.presentation.auth.RefreshTokenCookieProvider;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -88,8 +89,8 @@ public ResponseEntity<ExceptionResponse> handleValidationException(
.body(ExceptionResponse.from(stringBuilder.toString(), INVALID_REQUEST_BODY_TYPE));
}

@ExceptionHandler(RefreshTokenInvalidException.class)
public ResponseEntity<ExceptionResponse> handleRefreshTokenNotFoundException(final RefreshTokenInvalidException e,
@ExceptionHandler({RefreshTokenNotFoundException.class, RefreshTokenExpiredException.class})
public ResponseEntity<ExceptionResponse> handleRefreshTokenNotFoundException(final UnauthorizedException e,
final HttpServletRequest request,
final HttpServletResponse response) {
refreshTokenCookieProvider.removeCookie(request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.woowacourse.f12.dto.result.LoginResult;
import com.woowacourse.f12.exception.forbidden.NotAdminException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenExpiredException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenInvalidException;
import com.woowacourse.f12.exception.unauthorized.RefreshTokenNotFoundException;
import java.time.LocalDateTime;
import java.util.Optional;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -238,7 +238,7 @@ class AuthServiceTest {

// when, then
assertThatThrownBy(() -> authService.issueAccessToken("refreshToken"))
.isExactlyInstanceOf(RefreshTokenInvalidException.class);
.isExactlyInstanceOf(RefreshTokenNotFoundException.class);
}

@Test
Expand Down
Loading