Skip to content

Commit 6e2203d

Browse files
authored
Merge pull request #192 from prgrms-web-devcourse-final-project/fix/Report-Ai(WR9-115)
fix: Ai 로그찍기
2 parents 7a30c97 + 3825d85 commit 6e2203d

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/main/java/io/crops/warmletter/domain/report/service/ReportModerationService.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.crops.warmletter.domain.report.service;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
34
import io.crops.warmletter.domain.report.enums.ReasonType;
45
import lombok.RequiredArgsConstructor;
56
import lombok.extern.slf4j.Slf4j;
@@ -26,14 +27,30 @@ public Map<String, String> moderateText(String text, ReasonType reasonType, Stri
2627
Map<String, Object> requestBody = buildRequestBody(prompt);
2728
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
2829

29-
ResponseEntity<Map> response = new RestTemplate().exchange(apiUrl, HttpMethod.POST, requestEntity, Map.class);
30+
log.info("사용 중인 API URL: {}", apiUrl);
3031

31-
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
32-
log.info("AI Studio 응답: {}", response.getBody());
33-
Map<String, String> result = parseResponse(response.getBody());
34-
if (result != null) {
35-
return result;
32+
try {
33+
ObjectMapper objectMapper = new ObjectMapper();
34+
String jsonRequestBody = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(requestBody);
35+
36+
log.info("API 요청 시작 - URL: {}", apiUrl);
37+
log.info("JSON 요청 바디: \n{}", jsonRequestBody);
38+
log.info("요청 헤더: {}", headers);
39+
40+
ResponseEntity<Map> response = new RestTemplate().exchange(apiUrl, HttpMethod.POST, requestEntity, Map.class);
41+
42+
43+
log.info("API 응답 코드: {}", response.getStatusCode());
44+
log.info("API 응답 바디: {}", response.getBody());
45+
46+
if (response.getStatusCode() == HttpStatus.OK && response.getBody() != null) {
47+
Map<String, String> result = parseResponse(response.getBody());
48+
if (result != null) {
49+
return result;
50+
}
3651
}
52+
} catch (Exception e) {
53+
log.error("🚨 API 요청 실패: {}", e.getMessage(), e);
3754
}
3855
return defaultResult("AI 응답 없음 또는 오류 발생");
3956
}

0 commit comments

Comments
 (0)