Class: Vodka::Client::Middleware::ErrorAware

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/vodka/client/middleware/error_aware.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/vodka/client/middleware/error_aware.rb', line 5

def on_complete(env)
  env[:body] = MultiJson.load(env[:body]) unless env[:body].is_a?(Hash)
  return unless env[:body][:errors].present? && env[:body][:errors][:vodka_error].present?

  case env[:body][:errors][:vodka_error]
  when ForbiddenException::MESSAGE
    raise ForbiddenException.new
  when NotFoundException::MESSAGE
    raise NotFoundException.new
  else
    raise Exception.new(env[:body][:errors][:vodka_error])
  end
end