Skip to content

Commit 2cae8cd

Browse files
authored
Added RetryConditions option to Request level (#436)
1 parent d1979b9 commit 2cae8cd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ func (c *Client) SetRetryAfter(callback RetryAfterFunc) *Client {
589589
// AddRetryCondition method adds a retry condition function to array of functions
590590
// that are checked to determine if the request is retried. The request will
591591
// retry if any of the functions return true and error is nil.
592+
//
593+
// Note: These retry conditions are applied on all Request made using this Client.
594+
// For Request specific retry conditions check *Request.AddRetryCondition
592595
func (c *Client) AddRetryCondition(condition RetryConditionFunc) *Client {
593596
c.RetryConditions = append(c.RetryConditions, condition)
594597
return c

request.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type Request struct {
6767
clientTrace *clientTrace
6868
multipartFiles []*File
6969
multipartFields []*MultipartField
70+
retryConditions []RetryConditionFunc
7071
}
7172

7273
// Context method returns the Context if its already set in request
@@ -593,6 +594,16 @@ func (r *Request) SetCookies(rs []*http.Cookie) *Request {
593594
return r
594595
}
595596

597+
// AddRetryCondition method adds a retry condition function to the request's
598+
// array of functions that are checked to determine if the request is retried.
599+
// The request will retry if any of the functions return true and error is nil.
600+
//
601+
// Note: These retry conditions are checked before all retry conditions of the client.
602+
func (r *Request) AddRetryCondition(condition RetryConditionFunc) *Request {
603+
r.retryConditions = append(r.retryConditions, condition)
604+
return r
605+
}
606+
596607
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
597608
// HTTP request tracing
598609
//_______________________________________________________________________
@@ -763,7 +774,7 @@ func (r *Request) Execute(method, url string) (*Response, error) {
763774
Retries(r.client.RetryCount),
764775
WaitTime(r.client.RetryWaitTime),
765776
MaxWaitTime(r.client.RetryMaxWaitTime),
766-
RetryConditions(r.client.RetryConditions),
777+
RetryConditions(append(r.retryConditions, r.client.RetryConditions...)),
767778
RetryHooks(r.client.RetryHooks),
768779
)
769780

0 commit comments

Comments
 (0)