class Faraday::Response::RaiseHttp4xx

@private

Public Instance Methods

on_complete(env) click to toggle source
# File lib/faraday/response/raise_http_4xx.rb, line 7
def on_complete(env)
  case env[:status].to_i
  when 400
    raise SalesforceChatter::BadRequest.new(error_message(env), env[:response_headers])
  when 401
    raise SalesforceChatter::Unauthorized.new(error_message(env), env[:response_headers])
  when 403
    raise SalesforceChatter::Forbidden.new(error_message(env), env[:response_headers])
  when 404
    raise SalesforceChatter::NotFound.new(error_message(env), env[:response_headers])
  when 406
    raise SalesforceChatter::NotAcceptable.new(error_message(env), env[:response_headers])
  when 420
    raise SalesforceChatter::EnhanceYourCalm.new(error_message(env), env[:response_headers])
  end
end

Private Instance Methods

error_body(body) click to toggle source
# File lib/faraday/response/raise_http_4xx.rb, line 30
def error_body(body)
  if body.nil?
    nil
  elsif body['error']
    ": #{body['error']}"
  elsif body['errors']
    first = Array(body['errors']).first
    if first.kind_of? Hash
      ": #{first['message'].chomp}"
    else
      ": #{first.chomp}"
    end
  end
end
error_message(env) click to toggle source
# File lib/faraday/response/raise_http_4xx.rb, line 26
def error_message(env)
  "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}"
end