Exception: Conekta::Error

Inherits:
Exception
  • Object
show all
Defined in:
lib/conekta/error.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(message=nil, message_to_purchaser=nil, type=nil, code=nil, param=nil)
  @message = message
  @message_to_purchaser = message_to_purchaser
  @type = type
  @code = code
  @param = param
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/conekta/error.rb', line 6

def code
  @code
end

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/conekta/error.rb', line 3

def message
  @message
end

#message_to_purchaserObject (readonly)

Returns the value of attribute message_to_purchaser.



4
5
6
# File 'lib/conekta/error.rb', line 4

def message_to_purchaser
  @message_to_purchaser
end

#paramObject (readonly)

Returns the value of attribute param.



7
8
9
# File 'lib/conekta/error.rb', line 7

def param
  @param
end

#typeObject (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
47
48
# 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_purchaser',  { 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_nameObject



16
17
18
# File 'lib/conekta/error.rb', line 16

def class_name
  self.class.name.split('::')[-1]
end