Class: Simplewoo::Connection::ErrorMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/simplewoo/connection.rb

Overview

Middleware for responding to Errors returned from the api

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ErrorMiddleware

Returns a new instance of ErrorMiddleware.



56
57
58
# File 'lib/simplewoo/connection.rb', line 56

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/simplewoo/connection.rb', line 60

def call(env)
  @app.call(env).on_complete do |env|
    if error = Simplewoo::Error.from(env[:response])
      raise error
    end
  end
end