6
6
7
7
class Retry {
8
8
9
- static boolean shouldSwitchRegionAndRetry (Response response , QiniuException exception ) {
9
+ static boolean shouldUploadAgain (Response response , QiniuException exception ) {
10
10
Response checkResponse = response ;
11
11
if (checkResponse == null && exception != null ) {
12
12
checkResponse = exception .response ;
@@ -23,19 +23,41 @@ static boolean shouldSwitchRegionAndRetry(Response response, QiniuException exce
23
23
}
24
24
25
25
static Boolean requestShouldRetry (Response response , QiniuException exception ) {
26
- if (exception != null && !exception .isUnrecoverable () && (exception .response == null || exception .response .needRetry ())) {
26
+ if (response != null && response .needRetry ()) {
27
+ return true ;
28
+ }
29
+
30
+ if (exception == null || exception .isUnrecoverable ()) {
31
+ return false ;
32
+ }
33
+
34
+ if (exception .response != null && exception .response .needRetry ()) {
27
35
// 异常需可恢复
28
36
return true ;
29
37
}
30
- return response == null || response .needRetry ();
38
+
39
+ return false ;
31
40
}
32
41
33
42
static Boolean requestShouldSwitchHost (Response response , QiniuException exception ) {
34
- if (exception != null && !exception .isUnrecoverable () && (exception .response == null || exception .response .needSwitchServer ())) {
43
+ if (response != null && response .needSwitchServer ()) {
44
+ return true ;
45
+ }
46
+
47
+ if (exception == null ) {
48
+ return true ;
49
+ }
50
+
51
+ if (exception .isUnrecoverable ()) {
52
+ return false ;
53
+ }
54
+
55
+ if (exception .response == null || exception .response .needSwitchServer ()) {
35
56
// 异常需可恢复
36
57
return true ;
37
58
}
38
- return response == null || response .needSwitchServer ();
59
+
60
+ return false ;
39
61
}
40
62
41
63
static Response retryRequestAction (RequestRetryConfig config , RequestRetryAction action ) throws QiniuException {
@@ -48,12 +70,15 @@ static Response retryRequestAction(RequestRetryConfig config, RequestRetryAction
48
70
}
49
71
50
72
Response response = null ;
73
+ QiniuException exception = null ;
74
+
51
75
int retryCount = 0 ;
52
76
53
77
do {
54
78
boolean shouldSwitchHost = false ;
55
79
boolean shouldRetry = false ;
56
- QiniuException exception = null ;
80
+
81
+ exception = null ;
57
82
String host = action .getRequestHost ();
58
83
try {
59
84
response = action .doRequest (host );
@@ -90,6 +115,10 @@ static Response retryRequestAction(RequestRetryConfig config, RequestRetryAction
90
115
91
116
} while (true );
92
117
118
+ if (exception != null ) {
119
+ throw exception ;
120
+ }
121
+
93
122
return response ;
94
123
}
95
124
0 commit comments