class GooglePlus::Response::RaiseClientError
Public Instance Methods
on_complete(env)
click to toggle source
# File lib/google_plus/response/raise_client_error.rb, line 13 def on_complete(env) case env[:status].to_i when 400 raise GooglePlus::Error::BadRequest.new(error_message(env), env[:response_headers]) when 401 raise GooglePlus::Error::Unauthorized.new(error_message(env), env[:response_headers]) when 403 raise GooglePlus::Error::Forbidden.new(error_message(env), env[:response_headers]) when 404 raise GooglePlus::Error::NotFound.new(error_message(env), env[:response_headers]) when 406 raise GooglePlus::Error::NotAcceptable.new(error_message(env), env[:response_headers]) when 420 raise GooglePlus::Error::EnhanceYourCalm.new(error_message(env), env[:response_headers]) end end
Private Instance Methods
error_body(body)
click to toggle source
# File lib/google_plus/response/raise_client_error.rb, line 36 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/google_plus/response/raise_client_error.rb, line 32 def error_message(env) "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}" end