Class: Faraday::ClientErrorHandling::Parser

Inherits:
Response::Middleware
  • Object
show all
Defined in:
lib/faraday/client_error_handling/parser.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/faraday/client_error_handling/parser.rb', line 4

def on_complete(env)
  binding.pry
  json = MultiJson.load(env[:body], symbolize_keys: true)

  errors = json.delete(:errors) || {}

  if defined?( Rails ) && !errors.empty?
    Rails.logger.warn "SERVICE ERRORS: #{errors}"
  end

   = json.delete(:metadata) || {}
  env[:body] = {
    data: json,
    errors: errors,
    metadata: 
  }
end