Skip to content

Commit

Permalink
Hotfix: npe fix
Browse files Browse the repository at this point in the history
  • Loading branch information
versatile0010 committed Nov 15, 2023
1 parent ea813a1 commit 3a732f2
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import java.util.Optional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
Expand All @@ -42,8 +44,9 @@ public GetTokenResponse loginKakao(GetTokenRequest tokenRequest) {
try {
ResponseEntity<KakaoInfoResponse> response = restTemplate.exchange(kakaoProperties.getUser_api_url(), HttpMethod.GET, new HttpEntity<>(null, headers), KakaoInfoResponse.class);
String email = response.getBody().getKakao_account().getEmail();
String realname = response.getBody().getKakao_account().getProfile().getNickname();
return getTokenResponse(email, realname);
String realName = Optional.ofNullable(response.getBody().getKakao_account().getProfile().getNickname())
.orElse("사용자");
return getTokenResponse(email, realName);
} catch (Exception e) {
throw new BadRequestSocialTokenException();
}
Expand All @@ -57,9 +60,11 @@ public GetTokenResponse loginNaver(GetTokenRequest tokenRequest) {

try {
ResponseEntity<NaverInfoResponse> response = restTemplate.exchange(naverProperties.getUser_api_url(), HttpMethod.GET, new HttpEntity<>(null, headers), NaverInfoResponse.class);

String email = response.getBody().getResponse().getEmail();
String realname = response.getBody().getResponse().getName();
return getTokenResponse(email, realname);
String realName = Optional.ofNullable(response.getBody().getResponse().getName())
.orElse("사용자");
return getTokenResponse(email, realName);
} catch (Exception e) {
throw new BadRequestSocialTokenException();
}
Expand Down

0 comments on commit 3a732f2

Please sign in to comment.