Exception: SimpleTwitter::Error
- Inherits:
-
StandardError
- Object
- StandardError
- SimpleTwitter::Error
- Defined in:
- lib/simple_twitter/error.rb
Overview
Error base class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Hash<Symbol, String>
readonly
Error response body.
-
#raw_response ⇒ HTTP::Response
readonly
Raw error response.
Instance Method Summary collapse
-
#initialize(raw_response) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(raw_response) ⇒ Error
Returns a new instance of Error.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/simple_twitter/error.rb', line 16 def initialize(raw_response) @raw_response = raw_response begin @body = JSON.parse(raw_response.to_s, symbolize_names: true) title = @body[:title] || "Unknown error" title << " (status #{raw_response.code})" super(title) rescue JSON::ParserError => e # Twitter doesn't returns json super("Unknown error (status #{raw_response.code})") end end |
Instance Attribute Details
#body ⇒ Hash<Symbol, String> (readonly)
Returns error response body.
12 13 14 |
# File 'lib/simple_twitter/error.rb', line 12 def body @body end |
#raw_response ⇒ HTTP::Response (readonly)
Returns raw error response.
7 8 9 |
# File 'lib/simple_twitter/error.rb', line 7 def raw_response @raw_response end |