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

🐛 [STMT-146] 표준 예외가 아닌 커스텀 예외를 사용하도록 변경 #99

Merged
merged 1 commit into from
Mar 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
public class IllegalKeyAlgorithmException extends AuthenticationException {
private final ErrorCode errorCode;

public IllegalKeyAlgorithmException(ErrorCode errorCode) {
super(errorCode.getMessage());
this.errorCode = errorCode;
}

public IllegalKeyAlgorithmException(ErrorCode errorCode, Throwable cause) {
super(errorCode.getMessage(), cause);
this.errorCode = errorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.stumeet.server.common.auth.exception;

import com.stumeet.server.common.response.ErrorCode;
import org.springframework.security.core.AuthenticationException;

public class NotExistsOAuthProviderException extends AuthenticationException {

public NotExistsOAuthProviderException(ErrorCode errorCode) {
super(errorCode.getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public PublicKey getSecretKey(ApplePublicKeyResponses publicKeys, String accessT
ApplePublicKeyResponses.ApplePublicKeyResponse applePublicKey = publicKeys.keys().stream()
.filter(key -> key.kid().equals(kid))
.findAny()
.orElseThrow(() -> new IllegalArgumentException("매칭되는 kid가 존재하지 않습니다."));
.orElseThrow(() -> new IllegalKeyAlgorithmException(ErrorCode.ILLEGAL_KEY_ALGORITHM_EXCEPTION));

BigInteger modulus = new BigInteger(1, Base64.getUrlDecoder().decode(applePublicKey.n()));
BigInteger publicExponent = new BigInteger(1, Base64.getUrlDecoder().decode(applePublicKey.e()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.stumeet.server.common.exception.model;

import com.stumeet.server.common.response.ErrorCode;

public class NotExistsException extends BusinessException {
public NotExistsException(String message, ErrorCode errorCode) {
super(message, errorCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum ErrorCode {
JWT_INVALID_SIGNATURE_EXCEPTION(HttpStatus.UNAUTHORIZED, "JWT 서명이 유효하지 않습니다."),
ILLEGAL_KEY_ALGORITHM_EXCEPTION(HttpStatus.UNAUTHORIZED, "유효하지 않은 키 알고리즘입니다."),
JWT_TOKEN_PARSING_EXCEPTION(HttpStatus.UNAUTHORIZED, "JWT 토큰 파싱에 실패했습니다."),
NOT_EXIST_OAUTH_PROVIDER(HttpStatus.UNAUTHORIZED, "존재하지 않는 OAuth 제공자입니다."),

/*
403 - FORBIDDEN
Expand All @@ -43,6 +44,7 @@ public enum ErrorCode {
404 - NOT FOUND
*/
STUDY_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 스터디 입니다."),
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 멤버 입니다."),

/*
500 - INTERNAL SERVER ERROR
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.stumeet.server.member.adapter.out.persistence;

import com.stumeet.server.common.annotation.PersistenceAdapter;
import com.stumeet.server.common.exception.model.NotExistsException;
import com.stumeet.server.common.response.ErrorCode;
import com.stumeet.server.member.application.port.out.MemberCommandPort;
import com.stumeet.server.member.application.port.out.MemberQueryPort;
import com.stumeet.server.member.domain.Member;
import com.stumeet.server.member.domain.OAuthProvider;
import com.stumeet.server.member.domain.exception.MemberNotExistsException;
import lombok.RequiredArgsConstructor;

@PersistenceAdapter
Expand Down Expand Up @@ -36,7 +39,7 @@ public Member getByOAuthProviderId(String oAuthProviderId, OAuthProvider provide
@Override
public Member getById(Long id) {
MemberJpaEntity memberJpaEntity = jpaMemberRepository.findById(id)
.orElseThrow(() -> new IllegalArgumentException("해당하는 ID의 유저가 존재하지 않습니다."));
.orElseThrow(() -> new MemberNotExistsException("해당하는 ID의 유저가 존재하지 않습니다. 전달받은 id : " + id, ErrorCode.MEMBER_NOT_FOUND));

return memberMapper.toDomain(memberJpaEntity);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.stumeet.server.member.domain;

import com.stumeet.server.common.auth.exception.NotExistsOAuthProviderException;
import com.stumeet.server.common.response.ErrorCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -17,6 +19,6 @@ public static OAuthProvider findByProvider(String provider) {
return Arrays.stream(values())
.filter(p -> p.getProvider().equals(provider))
.findAny()
.orElseThrow(() -> new IllegalArgumentException("알 수 없는 OAuth provider 입니다."));
.orElseThrow(() -> new NotExistsOAuthProviderException(ErrorCode.NOT_EXIST_OAUTH_PROVIDER));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.stumeet.server.member.domain.exception;

import com.stumeet.server.common.exception.model.NotExistsException;
import com.stumeet.server.common.response.ErrorCode;

public class MemberNotExistsException extends NotExistsException {
public MemberNotExistsException(String message, ErrorCode errorCode) {
super(message, errorCode);
}
}
Loading