Sha256: dc139a5d54a347401e31e5b6afc0c12183dca2c5c18fe9b3c3a50522c6f310dd

Contents?: true

Size: 759 Bytes

Versions: 11

Compression:

Stored size: 759 Bytes

Contents

# frozen_string_literal: true

# lib/errors.rb

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

11 entries across 11 versions & 1 rubygems

Version Path
stream-chat-ruby-2.11.2 lib/stream-chat/errors.rb
stream-chat-ruby-2.11.1 lib/stream-chat/errors.rb
stream-chat-ruby-2.11.0 lib/stream-chat/errors.rb
stream-chat-ruby-2.10.0 lib/stream-chat/errors.rb
stream-chat-ruby-2.9.0 lib/stream-chat/errors.rb
stream-chat-ruby-2.8.0 lib/stream-chat/errors.rb
stream-chat-ruby-2.6.0 lib/stream-chat/errors.rb
stream-chat-ruby-2.5.0 lib/stream-chat/errors.rb
stream-chat-ruby-2.4.0 lib/stream-chat/errors.rb
stream-chat-ruby-2.3.0 lib/stream-chat/errors.rb
stream-chat-ruby-2.2.0 lib/stream-chat/errors.rb