Sha256: b5ec68955a6695d6c6e3cdddf5887bf5fa9b3c0cb100ad7b8d06097564c06b6d

Contents?: true

Size: 668 Bytes

Versions: 3

Compression:

Stored size: 668 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.code, uri: response.request.last_uri.to_s }
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
telegram-bot-ruby-0.4.2 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.4.1 lib/telegram/bot/exceptions/response_error.rb
telegram-bot-ruby-0.4.0 lib/telegram/bot/exceptions/response_error.rb