Class: GogoKit::Middleware::RaiseError
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- GogoKit::Middleware::RaiseError
- Defined in:
- lib/gogokit/middleware/raise_error.rb
Instance Method Summary collapse
- #call(request_env) ⇒ Object
- #error_message(response_env) ⇒ Object
-
#initialize(app) ⇒ RaiseError
constructor
A new instance of RaiseError.
Constructor Details
#initialize(app) ⇒ RaiseError
Returns a new instance of RaiseError.
7 8 9 |
# File 'lib/gogokit/middleware/raise_error.rb', line 7 def initialize(app) super app end |
Instance Method Details
#call(request_env) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/gogokit/middleware/raise_error.rb', line 11 def call(request_env) @app.call(request_env).on_complete do |response_env| if response_env[:status].to_i >= 400 api_error = GogoKit::ApiError.new api_error.response = response_env raise api_error, (response_env) end end end |
#error_message(response_env) ⇒ Object
21 22 23 24 |
# File 'lib/gogokit/middleware/raise_error.rb', line 21 def (response_env) "#{response_env[:method].to_s.upcase} #{response_env[:url]}:" \ " #{response_env[:status]}}" end |