Sha256: 3c8bf7b5a7bb268b925df0f44f72efe7e6eb2598fa3684a8776d24334be02334

Contents?: true

Size: 661 Bytes

Versions: 32

Compression:

Stored size: 661 Bytes

Contents

module Telegram
  module Bot
    module Exceptions
      class ResponseError < Base
        attr_reader :response

        def initialize(response)
          @response = response
        end

        def to_s
          super +
            format(' (%s)', data.map { |k, v| %(#{k}: "#{v}") }.join(', '))
        end

        def error_code
          data[:error_code] || data['error_code']
        end

        private

        def data
          @data ||= begin
            JSON.parse(response.body)
          rescue JSON::ParserError
            { error_code: response.status, uri: response.env.url.to_s }
          end
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 2 rubygems

Version Path
telegram-bot-ruby-0.8.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.8.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.7.2 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.7.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.7.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.6.0.2 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.6.0.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.5.3 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.5.2 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.5.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.5.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.5.0.beta4 lib/telegram/bot/exceptions/response_error.rb