Exception: StreamChat::StreamAPIException

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Returns the value of attribute error_message.



12
13
14
# File 'lib/stream-chat/errors.rb', line 12

def error_message
  @error_message
end

#json_responseObject (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

#responseObject (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

#messageObject



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

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

#to_sObject



44
45
46
# File 'lib/stream-chat/errors.rb', line 44

def to_s
  message
end