| Total Complexity | 3 |
| Total Lines | 21 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 1 |
| 1 | require "faraday/middleware" |
||
| 6 | class Retry < Faraday::Middleware |
||
| 7 | attr_reader :retry_util |
||
| 8 | |||
| 9 | def initialize(app, opts = {}) |
||
| 10 | super app |
||
| 11 | @retry_util = FaradayMiddleware::Request::RetryUtil.new opts |
||
| 12 | end |
||
| 13 | |||
| 14 | def call(env) |
||
| 15 | original_env = env.dup |
||
| 16 | response = @app.call env |
||
| 17 | |||
| 18 | retry_status = @retry_util.retry_status response.env[:status], response.env[:response_headers][:retry_after] |
||
| 19 | |||
| 20 | if retry_status |
||
| 21 | @app.call original_env |
||
| 22 | else |
||
| 23 | response |
||
| 24 | end |
||
| 25 | end |
||
| 26 | end |
||
| 27 | end |
||
| 63 |