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
Returns a new instance of StreamAPIException.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/stream-chat/errors.rb', line 25 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.
13 14 15 |
# File 'lib/stream-chat/errors.rb', line 13 def error_code @error_code end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
16 17 18 |
# File 'lib/stream-chat/errors.rb', line 16 def @error_message end |
#json_response ⇒ Object (readonly)
Returns the value of attribute json_response.
19 20 21 |
# File 'lib/stream-chat/errors.rb', line 19 def json_response @json_response end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
22 23 24 |
# File 'lib/stream-chat/errors.rb', line 22 def response @response end |
Instance Method Details
#message ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/stream-chat/errors.rb', line 39 def if @json_response "StreamChat error code #{@error_code}: #{@error_message}" else "StreamChat error HTTP code: #{@response.status}" end end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/stream-chat/errors.rb', line 48 def to_s end |