Exception: SimpleTwitter::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/simple_twitter/error.rb

Overview

Error base class

Direct Known Subclasses

ClientError, ServerError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Error

Returns a new instance of Error.

Parameters:

  • raw_response (HTTP::Response)

    raw error response from Twitter API

See Also:



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

#bodyHash<Symbol, String> (readonly)

Returns error response body.

Returns:

  • (Hash<Symbol, String>)

    error response body

See Also:



12
13
14
# File 'lib/simple_twitter/error.rb', line 12

def body
  @body
end

#raw_responseHTTP::Response (readonly)

Returns raw error response.

Returns:

  • (HTTP::Response)

    raw error response

See Also:



7
8
9
# File 'lib/simple_twitter/error.rb', line 7

def raw_response
  @raw_response
end