Exception: Twitter::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Twitter::Error
- Extended by:
- Utils
- Defined in:
- lib/twitter/error.rb
Overview
Custom error class for rescuing from all Twitter errors
Defined Under Namespace
Modules: Code
Constant Summary collapse
- ClientError =
Raised when Twitter returns a 4xx HTTP status code
Class.new(self)
- BadRequest =
Raised when Twitter returns the HTTP status code 400
Class.new(ClientError)
Class.new(ClientError)
- Forbidden =
Raised when Twitter returns the HTTP status code 403
Class.new(ClientError)
- RequestEntityTooLarge =
Raised when Twitter returns the HTTP status code 413
Class.new(ClientError)
- AlreadyFavorited =
Raised when a Tweet has already been favorited
Class.new(Forbidden)
- AlreadyRetweeted =
Raised when a Tweet has already been retweeted
Class.new(Forbidden)
- DuplicateStatus =
Raised when a Tweet has already been posted
Class.new(Forbidden)
- NotFound =
Raised when Twitter returns the HTTP status code 404
Class.new(ClientError)
- NotAcceptable =
Raised when Twitter returns the HTTP status code 406
Class.new(ClientError)
- UnprocessableEntity =
Raised when Twitter returns the HTTP status code 422
Class.new(ClientError)
- TooManyRequests =
Raised when Twitter returns the HTTP status code 429
Class.new(ClientError)
- ServerError =
Raised when Twitter returns a 5xx HTTP status code
Class.new(self)
- InternalServerError =
Raised when Twitter returns the HTTP status code 500
Class.new(ServerError)
- BadGateway =
Raised when Twitter returns the HTTP status code 502
Class.new(ServerError)
Class.new(ServerError)
- GatewayTimeout =
Raised when Twitter returns the HTTP status code 504
Class.new(ServerError)
- MediaError =
Raised when Twitter returns a media related error
Class.new(self)
- InvalidMedia =
Raised when Twitter returns an InvalidMedia error
Class.new(MediaError)
- MediaInternalError =
Raised when Twitter returns a media InternalError error
Class.new(MediaError)
- UnsupportedMedia =
Raised when Twitter returns an UnsupportedMedia error
Class.new(MediaError)
- TimeoutError =
Raised when an operation subject to timeout takes too long
Class.new(self)
- ERRORS =
{ 400 => Twitter::Error::BadRequest, 401 => Twitter::Error::Unauthorized, 403 => Twitter::Error::Forbidden, 404 => Twitter::Error::NotFound, 406 => Twitter::Error::NotAcceptable, 413 => Twitter::Error::RequestEntityTooLarge, 420 => Twitter::Error::TooManyRequests, 422 => Twitter::Error::UnprocessableEntity, 429 => Twitter::Error::TooManyRequests, 500 => Twitter::Error::InternalServerError, 502 => Twitter::Error::BadGateway, 503 => Twitter::Error::ServiceUnavailable, 504 => Twitter::Error::GatewayTimeout, }.freeze
- FORBIDDEN_MESSAGES =
proc do || case when /(?=.*status).*duplicate/i # - "Status is a duplicate." Twitter::Error::DuplicateStatus when /already favorited/i # - "You have already favorited this status." Twitter::Error::AlreadyFavorited when /already retweeted|Share validations failed/i # - "You have already retweeted this Tweet." (Nov 2017-) # - "You have already retweeted this tweet." (?-Nov 2017) # - "sharing is not permissible for this status (Share validations failed)" (-? 2017) Twitter::Error::AlreadyRetweeted end end
- MEDIA_ERRORS =
{ "InternalError" => Twitter::Error::MediaInternalError, "InvalidMedia" => Twitter::Error::InvalidMedia, "UnsupportedMedia" => Twitter::Error::UnsupportedMedia, }.freeze
Instance Attribute Summary collapse
- #code ⇒ Integer readonly
- #rate_limit ⇒ Twitter::RateLimit readonly
Class Method Summary collapse
-
.from_processing_response(error, headers) ⇒ Twitter::MediaError
Create a new error from a media error hash.
-
.from_response(body, headers) ⇒ Twitter::Error
Create a new error from an HTTP response.
Instance Method Summary collapse
-
#initialize(message = "", rate_limit = {}, code = nil) ⇒ Twitter::Error
constructor
Initializes a new Error object.
Methods included from Utils
Constructor Details
#initialize(message = "", rate_limit = {}, code = nil) ⇒ Twitter::Error
Initializes a new Error object
196 197 198 199 200 |
# File 'lib/twitter/error.rb', line 196 def initialize( = "", rate_limit = {}, code = nil) super() @rate_limit = Twitter::RateLimit.new(rate_limit) @code = code end |
Instance Attribute Details
#code ⇒ Integer (readonly)
7 8 9 |
# File 'lib/twitter/error.rb', line 7 def code @code end |
#rate_limit ⇒ Twitter::RateLimit (readonly)
9 10 11 |
# File 'lib/twitter/error.rb', line 9 def rate_limit @rate_limit end |
Class Method Details
.from_processing_response(error, headers) ⇒ Twitter::MediaError
Create a new error from a media error hash
161 162 163 164 165 166 |
# File 'lib/twitter/error.rb', line 161 def from_processing_response(error, headers) klass = MEDIA_ERRORS[error[:name]] || self = error[:message] code = error[:code] klass.new(, headers, code) end |
.from_response(body, headers) ⇒ Twitter::Error
Create a new error from an HTTP response
151 152 153 154 |
# File 'lib/twitter/error.rb', line 151 def from_response(body, headers) , code = parse_error(body) new(, headers, code) end |