Exception: StreamChat::StreamAPIException
- Inherits:
-
StandardError
- Object
- StandardError
- StreamChat::StreamAPIException
- Extended by:
- T::Sig
- 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.
-
#json_response ⇒ Object
readonly
Returns the value of attribute json_response.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response) ⇒ StreamAPIException
constructor
A new instance of StreamAPIException.
- #message ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(response) ⇒ StreamAPIException
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stream-chat/errors.rb', line 21 def initialize(response) super() @response = response begin parsed_response = JSON.parse(response.body) @json_response = T.let(true, T::Boolean) @error_code = T.let(parsed_response.fetch('code', 'unknown'), Integer) @error_message = T.let(parsed_response.fetch('message', 'unknown'), String) rescue JSON::ParserError @json_response = false end end |
Instance Attribute Details
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
9 10 11 |
# File 'lib/stream-chat/errors.rb', line 9 def error_code @error_code end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
12 13 14 |
# File 'lib/stream-chat/errors.rb', line 12 def @error_message end |
#json_response ⇒ Object (readonly)
Returns the value of attribute json_response.
15 16 17 |
# File 'lib/stream-chat/errors.rb', line 15 def json_response @json_response end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
18 19 20 |
# File 'lib/stream-chat/errors.rb', line 18 def response @response end |
Instance Method Details
#message ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/stream-chat/errors.rb', line 35 def if @json_response "StreamChat error code #{@error_code}: #{@error_message}" else "StreamChat error HTTP code: #{@response.status}" end end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/stream-chat/errors.rb', line 44 def to_s end |