Skip to content

Commit

Permalink
refactor: 예외 처리 로직 리팩토링
Browse files Browse the repository at this point in the history
일부 오류 및 코드 형태 깔끔하게 변경
  • Loading branch information
limjustin committed Feb 13, 2024
1 parent 904d95c commit 6bfe151
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/main/java/umc/meme/auth/global/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public AuthResponse.TokenDto login(AuthRequest.LoginDto loginDto) throws AuthExc
throw new LockedException("LOCKED_EXCEPTION", exception);
} catch (BadCredentialsException exception) {
throw new BadCredentialsException("BAD_CREDENTIALS_EXCEPTION", exception);
} catch (AuthException e) {
throw new AuthException(e.getBaseErrorCode());
} catch (AuthException exception) {
throw exception;
}

UserDetails userDetails = principalDetailsService.loadUserByUsername(userName);
Expand All @@ -68,9 +68,9 @@ public AuthResponse.TokenDto login(AuthRequest.LoginDto loginDto) throws AuthExc
private User getUser(AuthRequest.LoginDto loginDto) throws AuthException {
OAuthService oAuthService;

if (loginDto.getProvider() == "KAKAO") {
if (loginDto.getProvider().equals("KAKAO")) {
oAuthService = new KakaoAuthService(userRepository, redisRepository);
} else if (loginDto.getProvider() == "APPLE") {
} else if (loginDto.getProvider().equals("APPLE")) {
oAuthService = new AppleAuthService(userRepository, redisRepository);
} else {
throw new AuthException(ErrorStatus.PROVIDER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public enum ErrorStatus implements BaseErrorCode {
NOT_FOUND(HttpStatus.NOT_FOUND, 404, "요청한 주소로 응답을 받을 수 없습니다."),

PROVIDER_ERROR(HttpStatus.UNAUTHORIZED, 401, "지정한 소셜 로그인 방식을 찾을 수 없습니다."),

// 소셜 로그인 관련 에러
KEY_NOT_FOUND(HttpStatus.NOT_FOUND, 404, "일치하는 Web Key를 찾을 수 없습니다.");


Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package umc.meme.auth.global.exception;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import umc.meme.auth.global.common.BaseResponseDto;
import umc.meme.auth.global.common.status.ErrorStatus;
import umc.meme.auth.global.exception.handler.AuthException;

@RestControllerAdvice
public class ControllerAdvice {

@ExceptionHandler(value = AuthException.class)
public ResponseEntity<?> invokeError(AuthException e) {
System.out.println("=== AuthException.class ===");
System.out.println("HTTP_STATUS = " + e.getReason().getHttpStatus());
System.out.println("CODE = " + e.getReason().getCode());
System.out.println("REASON = " + e.getReason().getMessage());
return ResponseEntity.badRequest().build();
public BaseResponseDto<?> invokeError(AuthException e) {
return BaseResponseDto.ErrorResponse((ErrorStatus) e.getBaseErrorCode());
}
}
3 changes: 3 additions & 0 deletions src/main/java/umc/meme/auth/global/oauth/OAuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public User getUserInfo(String idToken) throws AuthException {
selectedKey = jsonWebKey;
}

if (selectedKey == null)
throw new AuthException(ErrorStatus.KEY_NOT_FOUND);

// 서명 검증
Claims claims = validateSignature(idToken, getRSAPublicKey(selectedKey));
userEmail = claims.get("email").toString();
Expand Down

0 comments on commit 6bfe151

Please sign in to comment.