Exception: StreamChat::StreamAPIException
- Inherits:
-
StandardError
- Object
- StandardError
- StreamChat::StreamAPIException
- Defined in:
- lib/stream-chat/errors.rb
Instance Attribute Summary collapse
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
Instance Method Summary collapse
-
#initialize(response) ⇒ StreamAPIException
constructor
A new instance of StreamAPIException.
- #json_response? ⇒ Boolean
- #message ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(response) ⇒ StreamAPIException
Returns a new instance of StreamAPIException.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/stream-chat/errors.rb', line 10 def initialize(response) super() @response = response begin parsed_response = JSON.parse(response.body) @json_response = true @error_code = parsed_response.fetch('code', 'unknown') @error_message = parsed_response.fetch('message', 'unknown') rescue JSON::ParserError @json_response = false end end |
Instance Attribute Details
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
7 8 9 |
# File 'lib/stream-chat/errors.rb', line 7 def error_code @error_code end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
8 9 10 |
# File 'lib/stream-chat/errors.rb', line 8 def @error_message end |
Instance Method Details
#json_response? ⇒ Boolean
31 32 33 |
# File 'lib/stream-chat/errors.rb', line 31 def json_response? @json_response end |
#message ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/stream-chat/errors.rb', line 23 def if @json_response "StreamChat error code #{@error_code}: #{@error_message}" else "StreamChat error HTTP code: #{@response.status}" end end |
#to_s ⇒ Object
35 36 37 |
# File 'lib/stream-chat/errors.rb', line 35 def to_s end |