Class: AngellistApi::Response::RaiseClientError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/angellist_api/response/raise_client_error.rb

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/angellist_api/response/raise_client_error.rb', line 12

def on_complete(env)
  case env[:status].to_i
  when 400
    raise AngellistApi::Error::BadRequest.new(error_message(env), env[:response_headers])
  when 401
    raise AngellistApi::Error::Unauthorized.new(error_message(env), env[:response_headers])
  when 403
    if env[:body]['error'] == 'over_limit'
      raise AngellistApi::Error::TooManyRequests.new(error_message(env), env[:response_headers])
    else
      raise AngellistApi::Error::Forbidden.new(error_message(env), env[:response_headers])
    end
  when 404
    raise AngellistApi::Error::NotFound.new(error_message(env), env[:response_headers])
  when 406
    raise AngellistApi::Error::NotAcceptable.new(error_message(env), env[:response_headers])
  end
end