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.18.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.17.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.16.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.15.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.14.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.13.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.12.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.11.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.10.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.10.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.9.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.9.0 lib/telegram/bot/exceptions/response_error.rb
dialog_bot_ruby-0.8.8 lib/telegram/bot/exceptions/response_error.rb
dialog_bot_ruby-0.8.7 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.8.6.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.8.6 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.8.5 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.8.4 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.8.3 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.8.2 lib/telegram/bot/exceptions/response_error.rb