Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.springframework.lang.NonNull;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.ResponseErrorHandler;

Expand All @@ -52,6 +53,7 @@
* @author Christian Tzolov
* @author SriVarshan P
* @author Seunggyu Lee
* @author Yanming Zhou
*/
@AutoConfiguration
@ConditionalOnClass(RetryUtils.class)
Expand Down Expand Up @@ -104,12 +106,9 @@ public void handleError(@NonNull URI url, @NonNull HttpMethod method, @NonNull C

@SuppressWarnings("removal")
public void handleError(@NonNull ClientHttpResponse response) throws IOException {
if (!response.getStatusCode().isError()) {
return;
}

String error = StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8);
if (error == null || error.isEmpty()) {
if (!StringUtils.hasLength(error)) {
error = "No response body available";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
*
* @author Christian Tzolov
* @author Soby Chacko
* @author Yanming Zhou
* @since 0.8.1
*/
public abstract class RetryUtils {
Expand Down Expand Up @@ -78,20 +79,18 @@ public void handleError(final URI url, final HttpMethod method, final @NonNull C

@SuppressWarnings("removal")
public void handleError(final @NonNull ClientHttpResponse response) throws IOException {
if (response.getStatusCode().isError()) {
String error = StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8);
String message = String.format("%s - %s", response.getStatusCode().value(), error);
/*
* Thrown on 4xx client errors, such as 401 - Incorrect API key provided,
* 401 - You must be a member of an organization to use the API, 429 -
* Rate limit reached for requests, 429 - You exceeded your current quota,
* please check your plan and billing details.
*/
if (response.getStatusCode().is4xxClientError()) {
throw new NonTransientAiException(message);
}
throw new TransientAiException(message);
String error = StreamUtils.copyToString(response.getBody(), StandardCharsets.UTF_8);
String message = String.format("%s - %s", response.getStatusCode().value(), error);
/*
* Thrown on 4xx client errors, such as 401 - Incorrect API key provided, 401
* - You must be a member of an organization to use the API, 429 - Rate limit
* reached for requests, 429 - You exceeded your current quota, please check
* your plan and billing details.
*/
if (response.getStatusCode().is4xxClientError()) {
throw new NonTransientAiException(message);
}
throw new TransientAiException(message);
}

};
Expand Down