File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,29 @@ module Async
77 module REST
88 module Wrapper
99 class Generic
10+ protected def response_for ( request )
11+ while true
12+ response = resource . call ( request )
13+
14+ if response . status == 429
15+ if retry_after = response . headers [ 'retry-after' ]
16+ sleep ( retry_after . to_f )
17+ else
18+ # Without the `retry-after` header, we can't determine how long to wait, so we just return the response.
19+ return response
20+ end
21+ else
22+ return response
23+ end
24+ end
25+ end
26+
1027 def call ( resource , method = "GET" , payload = nil , &block )
1128 request = ::Protocol ::HTTP ::Request [ method , nil ]
1229
1330 self . prepare_request ( request , payload )
1431
15- response = resource . call ( request )
32+ response = self . response_for ( request )
1633
1734 # If we exit this block because of an exception, we close the response. This ensures we don't have any dangling connections.
1835 begin
You can’t perform that action at this time.
0 commit comments