Class: JsonApiClient::Middleware::Status
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- JsonApiClient::Middleware::Status
- Defined in:
- lib/json_api_client/middleware/status.rb
Instance Method Summary collapse
- #call(environment) ⇒ Object
-
#initialize(app, options) ⇒ Status
constructor
A new instance of Status.
Constructor Details
#initialize(app, options) ⇒ Status
Returns a new instance of Status.
4 5 6 7 |
# File 'lib/json_api_client/middleware/status.rb', line 4 def initialize(app, ) super(app) @options = end |
Instance Method Details
#call(environment) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/json_api_client/middleware/status.rb', line 9 def call(environment) @app.call(environment).on_complete do |env| handle_status(env[:status], env) # look for meta[:status] if env[:body].is_a?(Hash) code = env[:body].fetch("meta", {}).fetch("status", 200).to_i handle_status(code, env) end end rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e raise Errors::ConnectionError.new environment, e.to_s end |