|
10 | 10 | import io.github.flashvayne.chatgpt.dto.ChatResponse;
|
11 | 11 | import io.github.flashvayne.chatgpt.service.ChatgptService;
|
12 | 12 | import lombok.extern.slf4j.Slf4j;
|
13 |
| -import org.springframework.http.HttpEntity; |
14 |
| -import org.springframework.http.HttpHeaders; |
15 |
| -import org.springframework.http.MediaType; |
16 |
| -import org.springframework.http.ResponseEntity; |
| 13 | +import org.springframework.http.*; |
17 | 14 | import org.springframework.stereotype.Service;
|
18 | 15 | import org.springframework.web.client.RestTemplate;
|
19 | 16 |
|
@@ -117,9 +114,9 @@ protected <T> HttpEntity<?> buildHttpEntity(T request) {
|
117 | 114 | protected <T> T getResponse(HttpEntity<?> httpEntity, Class<T> responseType, String url) {
|
118 | 115 | log.info("request url: {}, httpEntity: {}", url, httpEntity);
|
119 | 116 | ResponseEntity<T> responseEntity = restTemplate.postForEntity(url, httpEntity, responseType);
|
120 |
| - if (responseEntity.getStatusCode().isError()) { |
| 117 | + if (responseEntity.getStatusCodeValue() != HttpStatus.OK.value()) { |
121 | 118 | log.error("error response status: {}", responseEntity);
|
122 |
| - throw new ChatgptException("error response status :" + responseEntity.getStatusCode().value()); |
| 119 | + throw new ChatgptException("error response status :" + responseEntity.getStatusCodeValue()); |
123 | 120 | } else {
|
124 | 121 | log.info("response: {}", responseEntity);
|
125 | 122 | }
|
|
0 commit comments