Sha256: c4d15f7f7c8c9df2009b417d5b40ecf4714cbc07c518b654938593e19baceba4

Contents?: true

Size: 718 Bytes

Versions: 3

Compression:

Stored size: 718 Bytes

Contents

# lib/errors.rb

module StreamChat
  class StreamAPIException < StandardError
    
    def initialize(response)
      @response = response
      p 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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
stream-chat-ruby-1.1.3 lib/stream-chat/errors.rb
stream-chat-ruby-1.1.2 lib/stream-chat/errors.rb
stream-chat-ruby-1.1.1 lib/stream-chat/errors.rb