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(options = {}) ⇒ Error

Returns a new instance of Error.



10
11
12
13
14
15
16
17
18
# File 'lib/conekta/error.rb', line 10

def initialize(options={})
  @message = options["message"]
  @message_to_purchaser = options["message_to_purchaser"]
  @param = options["param"]
  @code = options["code"]
  @validation_error = options["validation_error"]
  @validation_error = options["custom_message"]
  @type = options["type"]
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



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

def code
  @code
end

#custom_messageObject (readonly)

NEW FIELDS



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

def custom_message
  @custom_message
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.



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

def message_to_purchaser
  @message_to_purchaser
end

#paramObject (readonly)

Returns the value of attribute param.



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

def param
  @param
end

#typeObject (readonly)

DEPRECATED.



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

def type
  @type
end

#validation_errorObject (readonly)

NEW FIELDS



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

def validation_error
  @validation_error
end

Class Method Details

.error_handler(response, http_status) ⇒ Object



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 22

def self.error_handler(response, http_status)
  if http_status.to_s.empty? || http_status == 0
    NoConnectionError.new({
      "message" => I18n.t('error.requestor.connection',  { base: Conekta.api_base, locale: :en }),
      "message_to_purchaser" => I18n.t('error.requestor.connection_purchaser',  { locale: Conekta.locale.to_sym })
      })
  else
    case http_status
    when 400
      MalformedRequestError.new(response)
    when 401
      AuthenticationError.new(response)
    when 402
      ProcessingError.new(response)
    when 404
      ResourceNotFoundError.new(response)
    when 422
      ParameterValidationError.new(response)
    when 500
      ApiError.new(response)
    else
      Error.new(response)
    end
  end
end

Instance Method Details

#class_nameObject



19
20
21
# File 'lib/conekta/error.rb', line 19

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