Sha256: 6c97f48ab16f0382eed1472a8ec3c7ce46f76810abd38f32d23cb92fdd38fe22

Contents?: true

Size: 667 Bytes

Versions: 2

Compression:

Stored size: 667 Bytes

Contents

# frozen_string_literal: true

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

        def initialize(response:)
          @response = response

          super("Telegram API has returned the error. (#{data.map { |k, v| %(#{k}: #{v.inspect}) }.join(', ')})")
        end

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

        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

2 entries across 2 versions & 1 rubygems

Version Path
telegram-bot-ruby-2.2.0 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-2.1.0 lib/telegram/bot/exceptions/response_error.rb