lib/pagarme/errors.rb in pagarme-0.15 vs lib/pagarme/errors.rb in pagarme-1.0
- old
+ new
@@ -1,20 +1,34 @@
module PagarMe
class PagarMeError < StandardError
- attr_reader :message
- attr_reader :original_error
+ attr_accessor :message
+ attr_accessor :parameter_name
+ attr_accessor :type
+ attr_accessor :url
+ attr_accessor :errors
- def initialize(message=nil, original_error=nil)
- @message = message
- @original_error = original_error
+ 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 TransactionError < PagarMeError
+ class RequestError < PagarMeError
end
class ConnectionError < PagarMeError
end