Exception: StreamChat::StreamAPIException

Inherits:
StandardError
  • Object
show all
Defined in:
lib/stream-chat/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_codeObject (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_messageObject (readonly)

Returns the value of attribute error_message.



8
9
10
# File 'lib/stream-chat/errors.rb', line 8

def error_message
  @error_message
end

Instance Method Details

#json_response?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/stream-chat/errors.rb', line 31

def json_response?
  @json_response
end

#messageObject



23
24
25
26
27
28
29
# File 'lib/stream-chat/errors.rb', line 23

def message
  if @json_response
    "StreamChat error code #{@error_code}: #{@error_message}"
  else
    "StreamChat error HTTP code: #{@response.status}"
  end
end

#to_sObject



35
36
37
# File 'lib/stream-chat/errors.rb', line 35

def to_s
  message
end