diff --git a/lib/twitter/response/raise_client_error.rb b/lib/twitter/response/raise_client_error.rb index 6cc7235b6..1ce3764bc 100644 --- a/lib/twitter/response/raise_client_error.rb +++ b/lib/twitter/response/raise_client_error.rb @@ -13,26 +13,22 @@ class RaiseClientError < Faraday::Response::Middleware def on_complete(env) case env[:status].to_i when 400 - raise Twitter::Error::BadRequest.new(error_message(env), env[:response_headers]) + raise Twitter::Error::BadRequest.new(error_body(env[:body]), env[:response_headers]) when 401 - raise Twitter::Error::Unauthorized.new(error_message(env), env[:response_headers]) + raise Twitter::Error::Unauthorized.new(error_body(env[:body]), env[:response_headers]) when 403 - raise Twitter::Error::Forbidden.new(error_message(env), env[:response_headers]) + raise Twitter::Error::Forbidden.new(error_body(env[:body]), env[:response_headers]) when 404 - raise Twitter::Error::NotFound.new(error_message(env), env[:response_headers]) + raise Twitter::Error::NotFound.new(error_body(env[:body]), env[:response_headers]) when 406 - raise Twitter::Error::NotAcceptable.new(error_message(env), env[:response_headers]) + raise Twitter::Error::NotAcceptable.new(error_body(env[:body]), env[:response_headers]) when 420 - raise Twitter::Error::EnhanceYourCalm.new(error_message(env), env[:response_headers]) + raise Twitter::Error::EnhanceYourCalm.new(error_body(env[:body]), env[:response_headers]) end end private - def error_message(env) - "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}#{error_body(env[:body])}" - end - def error_body(body) if body.nil? nil diff --git a/lib/twitter/response/raise_server_error.rb b/lib/twitter/response/raise_server_error.rb index 8b3ed52cf..07e72956f 100644 --- a/lib/twitter/response/raise_server_error.rb +++ b/lib/twitter/response/raise_server_error.rb @@ -10,20 +10,14 @@ class RaiseServerError < Faraday::Response::Middleware def on_complete(env) case env[:status].to_i when 500 - raise Twitter::Error::InternalServerError.new(error_message(env, "Something is technically wrong."), env[:response_headers]) + raise Twitter::Error::InternalServerError.new("Something is technically wrong.", env[:response_headers]) when 502 - raise Twitter::Error::BadGateway.new(error_message(env, "Twitter is down or being upgraded."), env[:response_headers]) + raise Twitter::Error::BadGateway.new("Twitter is down or being upgraded.", env[:response_headers]) when 503 - raise Twitter::Error::ServiceUnavailable.new(error_message(env, "(__-){ Twitter is over capacity."), env[:response_headers]) + raise Twitter::Error::ServiceUnavailable.new("(__-){ Twitter is over capacity.", env[:response_headers]) end end - private - - def error_message(env, body=nil) - "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{[env[:status].to_s + ':', body].compact.join(' ')} Check http://status.twitter.com/ for updates on the status of the Twitter service." - end - end end end