Class: Rack::Idempotent::DefaultRescue

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-idempotent/default_rescue.rb

Constant Summary collapse

GET_RETRY_HTTP_CODES =
[408, 502, 503, 504]
POST_RETRY_HTTP_CODES =
[502, 503, 504]
IDEMPOTENT_ERROR_CLASSES =
[Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::EHOSTUNREACH]

Instance Method Summary collapse

Instance Method Details

#call(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rack-idempotent/default_rescue.rb', line 6

def call(options={})
  exception = options[:exception]
  status = nil
  method = nil

  if exception
    return IDEMPOTENT_ERROR_CLASSES.include?(exception.class)
  end

  unless status && method
    status = options[:response].status
    method = options[:request].env["REQUEST_METHOD"]
  end

  if method == "GET"
    GET_RETRY_HTTP_CODES.include?(status)
  elsif method == "POST"
    POST_RETRY_HTTP_CODES.include?(status)
  else
    false
  end
end