Class: Notion::Faraday::Response::WrapError

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

Constant Summary collapse

UNAVAILABLE_ERROR_STATUSES =
(500..599).freeze

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



14
15
16
17
18
# File 'lib/notion/faraday/response/wrap_error.rb', line 14

def call(env)
  super
rescue ::Faraday::TimeoutError, ::Faraday::ConnectionFailed
  raise Notion::Api::Errors::TimeoutError.new('timeout_error', env.response)
end

#on_complete(env) ⇒ Object



8
9
10
11
12
# File 'lib/notion/faraday/response/wrap_error.rb', line 8

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

  raise Notion::Api::Errors::UnavailableError.new('unavailable_error', env.response)
end