TOP接口一共会重复三次
对HttpURLConnection进行了封装
对HttpURLConnection进行了封装
public <T extends TaobaoResponse> T execute(TaobaoRequest<T> request, String session) throws ApiException {
T rsp = null;
ApiException exp = null;
for (int i = 0; i <= maxRetryCount; i++) {
if (i > 0) {
if ((rsp != null && ((rsp.getSubCode() != null && rsp.getSubCode().startsWith("isp."))
|| (retryErrorCodes != null && retryErrorCodes.contains(rsp.getSubCode())))) || exp != null) {
sleepWithoutInterrupt(retryWaitTime);
log.warn(buildRetryLog(request.getApiMethodName(), request.getTextParams(), i));
} else {
break;
}
}
try {
rsp = super.execute(request, session);
if (rsp.isSuccess()) {
return rsp;
} else {
if (i == maxRetryCount && throwIfOverMaxRetry) {
throw RETRY_FAIL;
}
}
} catch (ApiException e) {
if (exp == null) {
exp = e;
}
}
}
if (exp != null) {
throw exp;
} else {
return rsp;
}
}
本文详细解析了TOP接口中的重试机制实现原理,包括如何通过封装HttpURLConnection进行请求发送,遇到特定错误时如何自动重试及等待策略,并介绍了重试次数限制与异常处理流程。
3416

被折叠的 条评论
为什么被折叠?



