Skip to content

Commit e82b03b

Browse files
authored
Merge pull request #239 from tencentyun/dev/error_code_retry
Dev/error code retry
2 parents f43d335 + 65a233e commit e82b03b

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.qcloud</groupId>
66
<artifactId>cos_api</artifactId>
7-
<version>5.6.244.2</version>
7+
<version>5.6.244.3</version>
88
<packaging>jar</packaging>
99
<name>cos-java-sdk</name>
1010
<description>java sdk for qcloud cos</description>

src/main/java/com/qcloud/cos/COSClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ public COSObject getObject(GetObjectRequest getObjectRequest)
11831183
* to wrap their code in try/catch blocks and check for this status code if they want to
11841184
* use constraints.
11851185
*/
1186-
if (cse.getStatusCode() == 412 || cse.getStatusCode() == 304) {
1186+
if ((cse.getStatusCode() == 412 && !clientConfig.isThrow412Directly()) || (cse.getStatusCode() == 304 && !clientConfig.isThrow304Directly())) {
11871187
return null;
11881188
}
11891189
throw cse;

src/main/java/com/qcloud/cos/ClientConfig.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public class ClientConfig {
141141

142142
private boolean addLogDebugHeader = true;
143143

144+
private boolean throw412Directly = false;
145+
146+
private boolean throw304Directly = false;
147+
144148
// 不传入region 用于后续调用List Buckets(获取所有的bucket信息)
145149
public ClientConfig() {
146150
super();
@@ -517,4 +521,20 @@ public boolean isAddLogDebugHeader() {
517521
public void setAddLogDebugHeader(boolean addLogDebugHeader) {
518522
this.addLogDebugHeader = addLogDebugHeader;
519523
}
524+
525+
public boolean isThrow412Directly() {
526+
return throw412Directly;
527+
}
528+
529+
public void setThrow412Directly(boolean throw412Directly) {
530+
this.throw412Directly = throw412Directly;
531+
}
532+
533+
public boolean isThrow304Directly() {
534+
return throw304Directly;
535+
}
536+
537+
public void setThrow304Directly(boolean throw304Directly) {
538+
this.throw304Directly = throw304Directly;
539+
}
520540
}

src/main/java/com/qcloud/cos/http/DefaultCosHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ private <Y extends CosServiceRequest> void changeEndpointForRetry(CosHttpRequest
832832
for (Header header : httpResponse.getAllHeaders()) {
833833
if (Objects.equals(header.getName(), Headers.REQUEST_ID)) {
834834
String value = CodecUtils.convertFromIso88591ToUtf8(header.getValue());
835-
if (!value.isEmpty()) {
835+
if (value != null && !value.isEmpty()) {
836836
return;
837837
}
838838
}

0 commit comments

Comments
 (0)