Exception: Conekta::Error
- Inherits:
-
Exception
- Object
- Exception
- Conekta::Error
- Defined in:
- lib/conekta/error.rb
Direct Known Subclasses
ApiError, AuthenticationError, MalformedRequestError, NoConnectionError, ParameterValidationError, ProcessingError, ResourceNotFoundError
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#message_to_purchaser ⇒ Object
readonly
Returns the value of attribute message_to_purchaser.
-
#param ⇒ Object
readonly
Returns the value of attribute param.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #class_name ⇒ Object
-
#initialize(message = nil, message_to_purchaser = nil, type = nil, code = nil, param = nil) ⇒ Error
constructor
A new instance of Error.
Constructor Details
#initialize(message = nil, message_to_purchaser = nil, type = nil, code = nil, param = nil) ⇒ Error
Returns a new instance of Error.
9 10 11 12 13 14 15 |
# File 'lib/conekta/error.rb', line 9 def initialize(=nil, =nil, type=nil, code=nil, param=nil) @message = @message_to_purchaser = @type = type @code = code @param = param end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
6 7 8 |
# File 'lib/conekta/error.rb', line 6 def code @code end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
3 4 5 |
# File 'lib/conekta/error.rb', line 3 def @message end |
#message_to_purchaser ⇒ Object (readonly)
Returns the value of attribute message_to_purchaser.
4 5 6 |
# File 'lib/conekta/error.rb', line 4 def @message_to_purchaser end |
#param ⇒ Object (readonly)
Returns the value of attribute param.
7 8 9 |
# File 'lib/conekta/error.rb', line 7 def param @param end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/conekta/error.rb', line 5 def type @type end |
Class Method Details
.error_handler(resp, code) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/conekta/error.rb', line 19 def self.error_handler(resp, code) if resp.instance_of?(Hash) @message = resp["message"] if resp.has_key?('message') @message_to_purchaser = resp["message_to_purchaser"] if resp.has_key?('message_to_purchaser') @type = resp["type"] if resp.has_key?('type') @code = resp["code"] if resp.has_key?('code') @param = resp["param"] if resp.has_key?('param') end if code == nil or code == 0 or code == nil or code == "" raise NoConnectionError.new(I18n.t('error.requestor.connection', {base: Conekta.api_base, locale: :en}), I18n.t('error.requestor.connection', {base: Conekta.api_base, locale: Conekta.locale.to_sym})) end case code when 400 raise MalformedRequestError.new(@message, @message_to_purchaser, @type, @code, @params) when 401 raise AuthenticationError.new(@message, @message_to_purchaser, @type, @code, @params) when 402 raise ProcessingError.new(@message, @message_to_purchaser, @type, @code, @params) when 404 raise ResourceNotFoundError.new(@message, @message_to_purchaser, @type, @code, @params) when 422 raise ParameterValidationError.new(@message, @message_to_purchaser, @type, @code, @params) when 500 raise ApiError.new(@message, @message_to_purchaser, @type, @code, @params) else raise Error.new(@message, @message_to_purchaser, @type, @code, @params) end end |
Instance Method Details
#class_name ⇒ Object
16 17 18 |
# File 'lib/conekta/error.rb', line 16 def class_name self.class.name.split('::')[-1] end |