Sha256: 8d7f33e4b5225f1dadd4cf8c2317abe8e9e8002973831bd440fa16c473204dcb

Contents?: true

Size: 909 Bytes

Versions: 8

Compression:

Stored size: 909 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.initFromServerResponse(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

8 entries across 8 versions & 1 rubygems

Version Path
pagarme-1.10.0 lib/pagarme/errors.rb
pagarme-1.9.9 lib/pagarme/errors.rb
pagarme-1.9.8 lib/pagarme/errors.rb
pagarme-1.9.7 lib/pagarme/errors.rb
pagarme-1.9.6 lib/pagarme/errors.rb
pagarme-1.9.5 lib/pagarme/errors.rb
pagarme-1.9.4 lib/pagarme/errors.rb
pagarme-1.9.3 lib/pagarme/errors.rb