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
28
29
30
31
32
33
34
# File 'lib/rack-idempotent/default_rescue.rb', line 6

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

  if exception
    if IDEMPOTENT_ERROR_CLASSES.include?(exception.class)
      return true
    elsif exception.class == Rack::Idempotent::HTTPException
      status = exception.status
      method = exception.request.env["REQUEST_METHOD"]
    else
      return false
    end
  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