Class: Subordinate::Connection::ErrorMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/subordinate/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.


28
29
30
# File 'lib/subordinate/connection.rb', line 28

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object


32
33
34
35
36
37
38
# File 'lib/subordinate/connection.rb', line 32

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