lib/creditsafe/messages.rb in creditsafe-0.1.1 vs lib/creditsafe/messages.rb in creditsafe-0.2.0
- old
+ new
@@ -1,5 +1,7 @@
+require 'creditsafe/errors'
+
module Creditsafe
module Messages
class Message
attr_reader :code, :message, :error
@@ -10,9 +12,21 @@
@message = message
@error = error
end
alias error? error
+
+ def error_class
+ return unless error?
+
+ case code[1].to_i
+ when 1 then Creditsafe::DataError
+ when 2 then Creditsafe::AccountError
+ when 3 then Creditsafe::RequestError
+ when 4 then Creditsafe::ProcessingError
+ else Creditsafe::UnknownApiError
+ end
+ end
end
# rubocop:disable Metrics/LineLength
NO_RESULTS = Message.new(code: '010101', message: 'No results')
TOO_MANY_RESULTS = Message.new(code: '010102', message: 'Too many results')