@@ -60,23 +60,26 @@ func newClient(oauthClientID, oauthClientSecret, oauthAuthURL, oauthTokenURL, re
60
60
return client , nil
61
61
}
62
62
63
- // getWithRetry calls get() and retries on HTTP failure
64
- // (response code != 200 ).
63
+ // getWithRetry calls get() and retries on HTTP temp failure
64
+ // (response code 500-599 ).
65
65
func getWithRetry (hc * http.Client , url string ) (* http.Response , error ) {
66
66
backoff := lib.Backoff {}
67
67
for {
68
68
response , err := get (hc , url )
69
69
if response != nil && response .StatusCode == http .StatusOK {
70
70
return response , err
71
- }
72
-
73
- p , retryAgain := backoff .Pause ()
74
- if ! retryAgain {
75
- log .Debugf ("HTTP error %s, retry timeout hit" , err , p )
71
+ } else if response != nil && response .StatusCode >= 500 && response .StatusCode <= 599 {
72
+ p , retryAgain := backoff .Pause ()
73
+ if ! retryAgain {
74
+ log .Debugf ("HTTP error %s, retry timeout hit" , err )
75
+ return response , err
76
+ }
77
+ log .Debugf ("HTTP error %s, retrying after %s" , err , p )
78
+ time .Sleep (p )
79
+ } else {
80
+ log .Debugf ("Permanent HTTP error %s, will not retry" , err )
76
81
return response , err
77
82
}
78
- log .Debugf ("HTTP error %s, retrying after %s" , err , p )
79
- time .Sleep (p )
80
83
}
81
84
}
82
85
@@ -95,32 +98,35 @@ func get(hc *http.Client, url string) (*http.Response, error) {
95
98
response , err := hc .Do (request )
96
99
lock .Release ()
97
100
if err != nil {
98
- return nil , fmt .Errorf ("GET failure: %s" , err )
101
+ return response , fmt .Errorf ("GET failure: %s" , err )
99
102
}
100
103
if response .StatusCode != http .StatusOK {
101
- return nil , fmt .Errorf ("GET HTTP-level failure: %s %s" , url , response .Status )
104
+ return response , fmt .Errorf ("GET HTTP-level failure: %s %s" , url , response .Status )
102
105
}
103
106
104
107
return response , nil
105
108
}
106
109
107
- // postWithRetry calls post() and retries on HTTP failure
108
- // (response code != 200 ).
110
+ // postWithRetry calls post() and retries on HTTP temp failure
111
+ // (response code 500-599 ).
109
112
func postWithRetry (hc * http.Client , url string , form url.Values ) ([]byte , uint , int , error ) {
110
113
backoff := lib.Backoff {}
111
114
for {
112
115
responseBody , gcpErrorCode , httpStatusCode , err := post (hc , url , form )
113
116
if responseBody != nil && httpStatusCode == http .StatusOK {
114
117
return responseBody , gcpErrorCode , httpStatusCode , err
115
- }
116
-
117
- p , retryAgain := backoff .Pause ()
118
- if ! retryAgain {
119
- log .Debugf ("HTTP error %s, retry timeout hit" , err , p )
118
+ } else if responseBody != nil && httpStatusCode >= 500 && httpStatusCode <= 599 {
119
+ p , retryAgain := backoff .Pause ()
120
+ if ! retryAgain {
121
+ log .Debugf ("HTTP error %s, retry timeout hit" , err )
122
+ return responseBody , gcpErrorCode , httpStatusCode , err
123
+ }
124
+ log .Debugf ("HTTP error %s, retrying after %s" , err , p )
125
+ time .Sleep (p )
126
+ } else {
127
+ log .Debugf ("Permanent HTTP error %s, will not retry" , err )
120
128
return responseBody , gcpErrorCode , httpStatusCode , err
121
129
}
122
- log .Debugf ("HTTP error %s, retrying after %s" , err , p )
123
- time .Sleep (p )
124
130
}
125
131
}
126
132
0 commit comments