Class: Idempotent::DefaultRescue

Inherits:
Object
  • Object
show all
Defined in:
lib/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(request, response, exception) ⇒ Object



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

def call(request, response, exception)
  status = nil
  method = nil

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

  unless status && method
    status = response.status
    method = 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