Exception: Twitter::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/twitter/error.rb,
lib/twitter/error/forbidden.rb,
lib/twitter/error/not_found.rb,
lib/twitter/error/bad_gateway.rb,
lib/twitter/error/bad_request.rb,
lib/twitter/error/client_error.rb,
lib/twitter/error/server_error.rb,
lib/twitter/error/decode_error.rb,
lib/twitter/error/unauthorized.rb,
lib/twitter/error/not_acceptable.rb,
lib/twitter/error/gateway_timeout.rb,
lib/twitter/error/already_retweeted.rb,
lib/twitter/error/too_many_requests.rb,
lib/twitter/error/already_favorited.rb,
lib/twitter/error/service_unavailable.rb,
lib/twitter/error/configuration_error.rb,
lib/twitter/error/unprocessable_entity.rb,
lib/twitter/error/internal_server_error.rb,
lib/twitter/error/identity_map_key_error.rb

Overview

Custom error class for rescuing from all Twitter errors

Direct Known Subclasses

AlreadyFavorited, AlreadyRetweeted, ClientError, DecodeError, ServerError

Defined Under Namespace

Classes: AlreadyFavorited, AlreadyRetweeted, BadGateway, BadRequest, ClientError, ConfigurationError, DecodeError, Forbidden, GatewayTimeout, IdentityMapKeyError, InternalServerError, NotAcceptable, NotFound, ServerError, ServiceUnavailable, TooManyRequests, Unauthorized, UnprocessableEntity

Constant Summary

EnhanceYourCalm =
TooManyRequests
RateLimited =
TooManyRequests

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Twitter::Error) initialize(exception = $!, response_headers = {})

Initializes a new Error object

Parameters:

  • exception (Exception, String) (defaults to: $!)
  • response_headers (Hash) (defaults to: {})


23
24
25
26
27
# File 'lib/twitter/error.rb', line 23

def initialize(exception=$!, response_headers={})
  @rate_limit = Twitter::RateLimit.new(response_headers)
  @wrapped_exception = exception
  exception.respond_to?(:backtrace) ? super(exception.message) : super(exception.to_s)
end

Instance Attribute Details

- (Object) rate_limit (readonly)

Returns the value of attribute rate_limit



6
7
8
# File 'lib/twitter/error.rb', line 6

def rate_limit
  @rate_limit
end

- (Object) wrapped_exception (readonly)

Returns the value of attribute wrapped_exception



6
7
8
# File 'lib/twitter/error.rb', line 6

def wrapped_exception
  @wrapped_exception
end

Class Method Details

+ (Array) descendants

Returns:

  • (Array)


14
15
16
# File 'lib/twitter/error.rb', line 14

def self.descendants
  ObjectSpace.each_object(::Class).select{|klass| klass < self}
end

+ (Hash) errors

Returns:

  • (Hash)


9
10
11
# File 'lib/twitter/error.rb', line 9

def self.errors
  @errors ||= Hash[descendants.map{|klass| [klass.const_get(:HTTP_STATUS_CODE), klass]}]
end

Instance Method Details

- (Object) backtrace



29
30
31
# File 'lib/twitter/error.rb', line 29

def backtrace
  @wrapped_exception.respond_to?(:backtrace) ? @wrapped_exception.backtrace : super
end