Class: Mrkt::FaradayMiddleware::Response

Inherits:
FaradayMiddleware::ParseJson
  • Object
show all
Defined in:
lib/mrkt/faraday_middleware/response.rb

Instance Method Summary collapse

Instance Method Details

#handle_errors!(errors) ⇒ Object



21
22
23
24
25
26
# File 'lib/mrkt/faraday_middleware/response.rb', line 21

def handle_errors!(errors)
  error = errors.first

  raise Mrkt::Errors::Unknown if error.nil?
  raise Mrkt::Errors.find_by_response_code(error[:code].to_i), error[:message]
end

#process_response(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/mrkt/faraday_middleware/response.rb', line 10

def process_response(env)
  super

  data = env[:body]

  raise Mrkt::Errors::EmptyResponse if data.nil?
  raise Mrkt::Errors::Error, data[:error_description] if data.key?(:error)

  handle_errors!(data[:errors]) unless data.fetch(:success, true)
end