Sha256: 320f553cdca7c889ef625c0ecea02472881e9800bc7f13e419c5367aae074556

Contents?: true

Size: 908 Bytes

Versions: 3

Compression:

Stored size: 908 Bytes

Contents

module PagarMe
  class PagarMeError < StandardError
    attr_accessor :message
    attr_accessor :parameter_name
    attr_accessor :type
    attr_accessor :url
    attr_accessor :errors

    def initialize(message = "", parameter_name = "", type = "", url = "") 
      self.message = message
      self.type = type
      self.parameter_name = parameter_name
      self.errors = []
    end

    def self.fromServerResponse(response = {})
      object = self.new

      response['errors'].map do |error|
        object.message += error['message'] + ', '
        object.errors << PagarMeError.new(error['message'],  error['parameter_name'], error['type'], response['url'])
      end

      object
    end

    def to_s
      "#{self.class.to_s} - #{message}"
    end
  end

  class RequestError < PagarMeError
  end

  class ConnectionError < PagarMeError
  end

  class ResponseError < PagarMeError
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pagarme-2.0.2 lib/pagarme/errors.rb
pagarme-2.0.1 lib/pagarme/errors.rb
pagarme-2.0.0 lib/pagarme/errors.rb