Class: AppnexusApi::Faraday::Response::RaiseHttpError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/appnexusapi/faraday/raise_http_error.rb

Instance Method Summary collapse

Instance Method Details

#error_message(response) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/appnexusapi/faraday/raise_http_error.rb', line 30

def error_message(response)
  msg = "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}"
  if errors = response[:body] && response[:body]["errors"]
    msg << "\n"
    msg << errors.join("\n")
  end
  msg
end

#on_complete(response) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/appnexusapi/faraday/raise_http_error.rb', line 5

def on_complete(response)
  case response[:status].to_i
  when 400
    raise AppnexusApi::BadRequest, error_message(response)
  when 401
    raise AppnexusApi::Unauthorized, error_message(response)
  when 403
    raise AppnexusApi::Forbidden, error_message(response)
  when 404
    raise AppnexusApi::NotFound, error_message(response)
  when 406
    raise AppnexusApi::NotAcceptable, error_message(response)
  when 422
    raise AppnexusApi::UnprocessableEntity, error_message(response)
  when 500
    raise AppnexusApi::InternalServerError, error_message(response)
  when 501
    raise AppnexusApi::NotImplemented, error_message(response)
  when 502
    raise AppnexusApi::BadGateway, error_message(response)
  when 503
    raise AppnexusApi::ServiceUnavailable, error_message(response)
  end
end