checkRateLimitError returns a *RateLimitError when resp indicates a rate limit (HTTP 403 or 429) with recognizable retry headers; otherwise nil. A nil resp returns nil.
(resp *http.Response, clk quartz.Clock, resetHeader string)
| 230 | // rate limit (HTTP 403 or 429) with recognizable retry headers; |
| 231 | // otherwise nil. A nil resp returns nil. |
| 232 | func checkRateLimitError(resp *http.Response, clk quartz.Clock, resetHeader string) error { |
| 233 | if resp == nil { |
| 234 | return nil |
| 235 | } |
| 236 | if resp.StatusCode != http.StatusForbidden && resp.StatusCode != http.StatusTooManyRequests { |
| 237 | return nil |
| 238 | } |
| 239 | if clk == nil { |
| 240 | clk = quartz.NewReal() |
| 241 | } |
| 242 | retryAfter := parseRetryAfter(resp.Header, resetHeader, clk) |
| 243 | if retryAfter <= 0 { |
| 244 | return nil |
| 245 | } |
| 246 | return &RateLimitError{RetryAfter: clk.Now().Add(retryAfter + RateLimitPadding)} |
| 247 | } |
| 248 | |
| 249 | // countDiffLines counts added and deleted lines in a unified diff. It excludes |
| 250 | // file header lines such as +++ b/file and --- a/file. |
no test coverage detected