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