Class: Callcredit::Middleware::CheckResponse
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Callcredit::Middleware::CheckResponse
- Defined in:
- lib/callcredit/middleware/check_response.rb
Instance Method Summary collapse
Instance Method Details
#call(env) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/callcredit/middleware/check_response.rb', line 4 def call(env) @app.call(env).on_complete do |env| unless results = env[:body]["Results"] raise InvalidResponseError.new( "Invalid response", env[:status], env) end if results["Errors"] errors = results["Errors"].values.flatten = errors.map { |e| e.is_a?(Hash) ? e["__content__"] : e } raise APIError.new(.join(" | "), env[:status], env) end response_values(env) end end |
#response_values(env) ⇒ Object
20 21 22 |
# File 'lib/callcredit/middleware/check_response.rb', line 20 def response_values(env) { status: env[:status], headers: env[:headers], body: env[:body] } end |