Class: Faraday::Response::Middleware

Inherits:
Middleware show all
Defined in:
lib/faraday/response.rb

Overview

Used for simple response middleware.

Direct Known Subclasses

Logger, RaiseError

Instance Method Summary collapse

Methods inherited from Middleware

adapter?, dependency, inherited, #initialize, loaded?, new

Methods included from MiddlewareRegistry

#lookup_middleware, #register_middleware

Constructor Details

This class inherits a constructor from Faraday::Middleware

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
# File 'lib/faraday/response.rb', line 7

def call(env)
  @app.call(env).on_complete do |environment|
    on_complete(environment)
  end
end

#on_complete(env) ⇒ Object

Override this to modify the environment after the response has finished. Calls the ‘parse` method if defined



15
16
17
18
19
# File 'lib/faraday/response.rb', line 15

def on_complete(env)
  if respond_to? :parse
    env[:body] = parse(env[:body]) unless [204,304].index env[:status]
  end
end