Class: Wepay::Middleware::CheckStatus

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/wepay/middleware.rb

Overview

Checks for errors in responses from Wepay, in which case it raises a ‘Wepay::ApiError` which contains the code and the message found in the response.

Raises:

  • Wepay::ApiError

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/wepay/middleware.rb', line 32

def on_complete(env)
  response = env[:body]
  if response.is_a?(Hash) && response["error"]
    type    = response["error"]
    message = response["error_description"]
    code    = response["error_code"]

    raise Wepay::ApiError.new(type, message, code)
  end
end