Skip to content

Commit

Permalink
#133 [fix] 애플 로그인 에러 핸들링 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
orijoon98 committed Sep 23, 2022
1 parent e159bcc commit a490f18
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ public class UnAuthorizedException extends HousException {
public UnAuthorizedException(String message) {
super(message, ErrorCode.UNAUTHORIZED_EXCEPTION);
}

public UnAuthorizedException(String message, ErrorCode errorCode) {
super(message, errorCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import hous.server.common.exception.UnAuthorizedException;
import hous.server.external.client.apple.dto.response.ApplePublicKeyResponse;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.ExpiredJwtException;
Expand All @@ -21,6 +22,8 @@
import java.util.Base64;
import java.util.Map;

import static hous.server.common.exception.ErrorCode.UNAUTHORIZED_INVALID_TOKEN_EXCEPTION;

@RequiredArgsConstructor
@Component
public class AppleTokenProviderImpl implements AppleTokenProvider {
Expand All @@ -42,10 +45,10 @@ public String getSocialIdFromIdToken(String idToken) {
.getBody();
return claims.getSubject(); // return socialId;
} catch (JsonProcessingException | InvalidKeySpecException | InvalidClaimException |
NoSuchAlgorithmException e) {
throw new IllegalArgumentException(String.format("잘못된 애플 idToken (%s) 입니다 (reason: %s)", idToken, e.getMessage()));
NoSuchAlgorithmException | IllegalArgumentException e) {
throw new UnAuthorizedException(String.format("잘못된 애플 idToken (%s) 입니다 (reason: %s)", idToken, e.getMessage()), UNAUTHORIZED_INVALID_TOKEN_EXCEPTION);
} catch (ExpiredJwtException e) {
throw new IllegalArgumentException(String.format("만료된 애플 idToken (%s) 입니다 (reason: %s)", idToken, e.getMessage()));
throw new UnAuthorizedException(String.format("만료된 애플 idToken (%s) 입니다 (reason: %s)", idToken, e.getMessage()), UNAUTHORIZED_INVALID_TOKEN_EXCEPTION);
}
}

Expand Down

0 comments on commit a490f18

Please sign in to comment.