Skip to content

Commit

Permalink
chore: add try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Kang1221 committed Aug 10, 2024
1 parent 4972e44 commit 5fc7d95
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/main/java/co/orange/ddanzi/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,32 @@ public String getKakaoEmail(String accessToken) throws JsonProcessingException {

log.info("HTTP 요청 보내기");
HttpEntity<String> kakaoUserInfoRequest = new HttpEntity<>(headers);
RestTemplate rt = new RestTemplate();
RestTemplate restTemplate = new RestTemplate();

ResponseEntity<String> response = rt.exchange(
"https://kapi.kakao.com/v2/user/me",
HttpMethod.GET,
kakaoUserInfoRequest,
String.class
);

log.info("응답 상태 코드: {}", response.getStatusCode());
log.info("응답 본문: {}", response.getBody());

log.info("응답 수신 성공");
String responseBody = response.getBody();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(responseBody);

String email = jsonNode.get("kakao_account").get("email").asText();

return email;
try {
ResponseEntity<String> response = restTemplate.exchange(
"https://kapi.kakao.com/v2/user/me",
HttpMethod.GET,
kakaoUserInfoRequest,
String.class
);

log.info("응답 상태 코드: {}", response.getStatusCode());
log.info("응답 본문: {}", response.getBody());

// responseBody에 있는 정보 꺼내기
String responseBody = response.getBody();
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(responseBody);
log.info("카카오 바디 정보 수집 성공");

String email = jsonNode.get("kakao_account").get("email").asText();
return email;

} catch (Exception e) {
log.error("카카오 API 요청 중 오류 발생: {}", e.getMessage(), e);
throw e;
}
}

private List<String> loadWordsFromFile(String classpath) throws IOException {
Expand Down

0 comments on commit 5fc7d95

Please sign in to comment.