Skip to content

Commit

Permalink
Remove Twitter::Error#cause
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jan 30, 2014
1 parent 71b26f4 commit a5748b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
20 changes: 9 additions & 11 deletions lib/twitter/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
module Twitter
# Custom error class for rescuing from all Twitter errors
class Error < StandardError
attr_reader :cause, :code, :rate_limit
alias_method :wrapped_exception, :cause
attr_reader :code, :rate_limit

# If error code is missing see https://dev.twitter.com/docs/error-codes-responses
module Code
Expand Down Expand Up @@ -33,11 +32,11 @@ module Code
class << self
# Create a new error from an HTTP response
#
# @param response [Hash]
# @param response [Faraday::Response]
# @return [Twitter::Error]
def from_response(response = {})
error, code = parse_error(response.body)
new(error, response.response_headers, code)
def from_response(response)
message, code = parse_error(response.body)
new(message, response.headers, code)
end

# @return [Hash]
Expand Down Expand Up @@ -83,14 +82,13 @@ def extract_message_from_errors(body)
# Initializes a new Error object
#
# @param exception [Exception, String]
# @param response_headers [Hash]
# @param rate_limit [Hash]
# @param code [Integer]
# @return [Twitter::Error]
def initialize(exception = $ERROR_INFO, response_headers = {}, code = nil)
@rate_limit = RateLimit.new(response_headers)
@cause = exception
def initialize(message = '', rate_limit = {}, code = nil)
super(message)
@rate_limit = Twitter::RateLimit.new(rate_limit)
@code = code
exception.respond_to?(:message) ? super(exception.message) : super(exception.to_s)
end

class ConfigurationError < ::ArgumentError; end
Expand Down
7 changes: 0 additions & 7 deletions spec/twitter/error_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
end
end

describe '#cause' do
it 'returns the cause' do
error = Twitter::Error.new(Faraday::Error::ClientError.new('Oops'))
expect(error.cause.class).to eq(Faraday::Error::ClientError)
end
end

Twitter::Error.errors.each do |status, exception|

[nil, 'error', 'errors'].each do |body|
Expand Down

0 comments on commit a5748b9

Please sign in to comment.