Module: HTTPX::Plugins::Retries
- Defined in:
- lib/httpx/plugins/retries.rb
Overview
This plugin adds support for retrying requests when certain errors happen.
Defined Under Namespace
Modules: InstanceMethods, RequestMethods
Constant Summary collapse
- MAX_RETRIES =
3
- IDEMPOTENT_METHODS =
TODO: pass max_retries in a configure/load block
%i[get options head put delete].freeze
- RETRYABLE_ERRORS =
[IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, (OpenSSL::SSL::SSLError if defined?(OpenSSL)), TimeoutError, Parser::Error, Errno::EINVAL, Errno::ETIMEDOUT].freeze
Class Method Summary collapse
Class Method Details
.extra_options(options) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/httpx/plugins/retries.rb', line 26 def self.() Class.new(.class) do # number of seconds after which one can retry the request def_option(:retry_after) do |num| # return early if callable unless num.respond_to?(:call) num = Integer(num) raise Error, ":retry_after must be positive" unless num.positive? end num end def_option(:max_retries) do |num| num = Integer(num) raise Error, ":max_retries must be positive" unless num.positive? num end def_option(:retry_change_requests) def_option(:retry_on) do |callback| raise ":retry_on must be called with the response" unless callback.respond_to?(:call) callback end end.new().merge(max_retries: MAX_RETRIES) end |