Class: RelicLink::Faraday::Response::WrapError

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/relic_link/faraday/response/wrap_error.rb

Overview

Middleware to wrap generic API errors and raise them as exceptions.

Constant Summary collapse

UNAVAILABLE_ERROR_STATUSES =
(500..599)

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
# File 'lib/relic_link/faraday/response/wrap_error.rb', line 16

def call(env)
  super
rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed
  raise RelicLink::Errors::TimeoutError, env.response
end

#on_complete(env) ⇒ Object



10
11
12
13
14
# File 'lib/relic_link/faraday/response/wrap_error.rb', line 10

def on_complete(env)
  return unless UNAVAILABLE_ERROR_STATUSES.cover?(env.status)

  raise RelicLink::Errors::UnavailableError, env.response
end