@@ -16,32 +16,37 @@ def self.make_request(path, retries: DEFAULT_RETRIES, base_delay: 0.25)
1616 uri = URI ( "#{ host } #{ path } " )
1717 attempts = 0
1818
19- begin
19+ while attempts < retries
2020 attempts += 1
21- req = Net ::HTTP ::Get . new ( uri )
22- req [ 'Referer' ] = "jekyll-hackclub"
2321
24- res = Net ::HTTP . start ( uri . hostname , uri . port , use_ssl : uri . scheme == "https" , open_timeout : 3 , read_timeout : 6 ) do |http |
25- http . request ( req )
22+ begin
23+ req = Net ::HTTP ::Get . new ( uri )
24+ req [ 'Referer' ] = "jekyll-hackclub"
25+
26+ res = Net ::HTTP . start ( uri . hostname , uri . port , use_ssl : uri . scheme == "https" , open_timeout : 3 , read_timeout : 6 ) do |http |
27+ http . request ( req )
28+ end
29+
30+ if RETRYABLE_STATUS_CODES . include? ( res . code . to_i )
31+ sleep ( base_delay * attempts ) if attempts < retries
32+ next
33+ end
34+
35+ return JSON . parse ( res . body ) , res
36+ rescue JSON ::ParserError
37+ return { } , res
38+ rescue => e
39+ if attempts < retries
40+ sleep ( base_delay * attempts )
41+ next
42+ end
43+
44+ warn "Request to #{ uri } failed after #{ attempts } attempts: #{ e } "
45+ return { } , nil
2646 end
27-
28- if RETRYABLE_STATUS_CODES . include? ( res . code . to_i ) && attempts < retries
29- sleep ( base_delay * attempts )
30- retry
31- end
32-
33- return JSON . parse ( res . body ) , res
34- rescue JSON ::ParserError
35- return { } , res
36- rescue => e
37- if attempts < retries
38- sleep ( base_delay * attempts )
39- retry
40- end
41-
42- warn "Request to #{ uri } failed after #{ attempts } attempts: #{ e } "
43- return { } , nil
4447 end
48+
49+ return { } , nil
4550 end
4651
4752 def self . get_emoji ( id )
0 commit comments