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 @@ -38,6 +38,7 @@
import org.springframework.retry.support.RetryTemplate;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StreamUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.ResponseErrorHandler;

/**
Expand All @@ -47,6 +48,7 @@
*
* @author Christian Tzolov
* @author SriVarshan P
* @author Yanming Zhou
*/
@AutoConfiguration
@ConditionalOnClass(RetryUtils.class)
Expand Down Expand Up @@ -88,12 +90,9 @@ public boolean hasError(@NonNull ClientHttpResponse response) throws IOException

@Override
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 @@ -41,6 +41,7 @@
*
* @author Christian Tzolov
* @author Soby Chacko
* @author Yanming Zhou
* @since 0.8.1
*/
public abstract class RetryUtils {
Expand All @@ -60,20 +61,18 @@ public void handleError(URI url, HttpMethod method, @NonNull ClientHttpResponse
@Override
@SuppressWarnings("removal")
public void handleError(@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