Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

37 lines (31 sloc) 0.966 kB
module Twitter
# Custom error class for rescuing from all Twitter errors
class Error < StandardError
attr_reader :rate_limit, :wrapped_exception
# @return [Hash]
def self.errors
@errors ||= Hash[descendants.map{|klass| [klass.const_get(:HTTP_STATUS_CODE), klass]}]
end
# @return [Array]
def self.descendants
ObjectSpace.each_object(::Class).select{|klass| klass < self}
end
# Initializes a new Error object
#
# @param exception [Exception, String]
# @param response_headers [Hash]
# @return [Twitter::Error]
def initialize(exception=$!, response_headers={})
@rate_limit = Twitter::RateLimit.new(response_headers)
if exception.respond_to?(:backtrace)
super(exception.message)
@wrapped_exception = exception
else
super(exception.to_s)
end
end
def backtrace
@wrapped_exception ? @wrapped_exception.backtrace : super
end
end
end
Jump to Line
Something went wrong with that request. Please try again.