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.



69
70
71
# File 'lib/simplewoo/connection.rb', line 69

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/simplewoo/connection.rb', line 73

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