Sha256: 3a3abab2b032607a9e8a0792a7c9a0cef003fb552b5221dc31eab14479fe54f3

Contents?: true

Size: 708 Bytes

Versions: 11

Compression:

Stored size: 708 Bytes

Contents

# frozen_string_literal: true

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

        def initialize(response)
          @response = response
          super
        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

11 entries across 11 versions & 1 rubygems

Version Path
telegram-bot-ruby-1.0.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-1.0.0.rc1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-1.0.0.pre lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.23.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.22.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.21.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.21.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.20.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.19.2 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.19.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.19.0 lib/telegram/bot/exceptions/response_error.rb