Skip to content

Commit

Permalink
fix: 예외처리 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
osoohynn committed Dec 2, 2024
1 parent b079683 commit fb3eeaa
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -93,9 +95,17 @@ private MessageDto getAnswer(ChatHistoryService personalPromptList) {

return MessageDto.of(assistantMessage);

} catch (HttpClientErrorException e) {
log.error("HTTP Client Error: Status - {}, Body - {}", e.getStatusCode(), e.getResponseBodyAsString());
throw new RuntimeException("API 호출 실패: " + e.getMessage());
} catch (HttpServerErrorException e) {
log.error("HTTP Server Error: Status - {}, Body - {}", e.getStatusCode(), e.getResponseBodyAsString());
throw new RuntimeException("서버 오류 발생: " + e.getMessage());
} catch (Exception e) {
return MessageDto.of("An error occurred while processing the response.");
log.error("Unexpected Error: ", e);
throw new RuntimeException("예기치 않은 오류 발생: " + e.getMessage());
}

}

@Override
Expand Down

0 comments on commit fb3eeaa

Please sign in to comment.