Class: HelloSign::Middleware::RaiseError

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

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/hello_sign/middleware/raise_error.rb', line 8

def on_complete(env)
  body = env[:body] and body.is_a?(Hash) or return

  error = body[:error] and begin
    exception   = Error.from_error_name(error[:error_name])
    message     = error[:error_msg]
    status_code = env[:response][:status]

    fail exception.new(message, status_code)
  end
end