class Twitter::Error
Custom error class for rescuing from all Twitter
errors
Constants
- AlreadyFavorited
Raised when a
Tweet
has already been favorited- AlreadyRetweeted
Raised when a
Tweet
has already been retweeted- BadGateway
Raised when
Twitter
returns the HTTP status code 502- BadRequest
Raised when
Twitter
returns the HTTP status code 400- ClientError
Raised when
Twitter
returns a 4xx HTTP status code- DuplicateStatus
Raised when a
Tweet
has already been posted- ERRORS
- FORBIDDEN_MESSAGES
- Forbidden
Raised when
Twitter
returns the HTTP status code 403- GatewayTimeout
Raised when
Twitter
returns the HTTP status code 504- InternalServerError
Raised when
Twitter
returns the HTTP status code 500- InvalidMedia
Raised when
Twitter
returns anInvalidMedia
error- MEDIA_ERRORS
- MediaError
Raised when
Twitter
returns a media related error- MediaInternalError
Raised when
Twitter
returns a media InternalError error- NotAcceptable
Raised when
Twitter
returns the HTTP status code 406- NotFound
Raised when
Twitter
returns the HTTP status code 404- RequestEntityTooLarge
Raised when
Twitter
returns the HTTP status code 413- ServerError
Raised when
Twitter
returns a 5xx HTTP status codeRaised when
Twitter
returns the HTTP status code 503- TimeoutError
Raised when an operation subject to timeout takes too long
- TooManyRequests
Raised when
Twitter
returns the HTTP status code 429Raised when
Twitter
returns the HTTP status code 401- UnprocessableEntity
Raised when
Twitter
returns the HTTP status code 422- UnsupportedMedia
Raised when
Twitter
returns anUnsupportedMedia
error
Attributes
@return [Integer]
@return [Twitter::RateLimit]
Public Class Methods
Create a new error from a media error hash
@param error [Hash] @param headers [Hash] @return [Twitter::MediaError]
# File lib/twitter/error.rb, line 160 def from_processing_response(error, headers) klass = MEDIA_ERRORS[error[:name]] || self message = error[:message] code = error[:code] klass.new(message, headers, code) end
Create a new error from an HTTP response
@param body [String] @param headers [Hash] @return [Twitter::Error]
# File lib/twitter/error.rb, line 150 def from_response(body, headers) message, code = parse_error(body) new(message, headers, code) end
Initializes a new Error
object
@param message [Exception, String] @param rate_limit
[Hash] @param code [Integer] @return [Twitter::Error]
# File lib/twitter/error.rb, line 195 def initialize(message = '', rate_limit = {}, code = nil) super(message) @rate_limit = Twitter::RateLimit.new(rate_limit) @code = code end
Private Class Methods
# File lib/twitter/error.rb, line 179 def extract_message_from_errors(body) first = Array(body[:errors]).first if first.is_a?(Hash) [first[:message].chomp, first[:code]] else [first.chomp, nil] end end
# File lib/twitter/error.rb, line 169 def parse_error(body) if body.nil? || body.empty? ['', nil] elsif body[:error] [body[:error], nil] elsif body[:errors] extract_message_from_errors(body) end end