Exception: Conekta::Error

Inherits:
StandardError
  • 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.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/conekta/error.rb', line 5

def initialize(options={})
  @type = options["type"]
  @log_id = options["log_id"]
  if options["details"]
    @details = options["details"].collect{|details|
      Conekta::ErrorDetails.new(details)
    }
  else
    temp_details = Conekta::ErrorDetails.new({
        "message" => options["message_to_purchaser"],
        "debug_message" => options["message"],
        "param" => options["param"]
      })
    @details = [temp_details]
  end
  @message = @details.first.debug_message
  @data = options["data"]

  super
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

#detailsObject (readonly)

Returns the value of attribute details.



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

def details
  @details
end

#log_idObject (readonly)

Returns the value of attribute log_id.



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

def log_id
  @log_id
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.error_handler(response, http_status) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/conekta/error.rb', line 30

def self.error_handler(response, http_status)
  if http_status.to_s.empty? || http_status == 0
    NoConnectionError.new({
      "details" => [
        {
          "debug_message" => I18n.translate(
            'error.requestor.connection',
            locale: :en,
            base: Conekta.api_base
          ),
          "message" => I18n.translate(
            'error.requestor.connection_purchaser',
            locale: Conekta.locale.to_sym
          ),
          "code" => "error.requestor.connection"
        }
      ]
    })
  else
    case http_status
    when -1, 0
      NoConnectionError.new(response)
    when 400
      MalformedRequestError.new(response)
    when 401
      AuthenticationError.new(response)
    when 402
      ProcessingError.new(response)
    when 404
      ResourceNotFoundError.new(response)
    when 409
      VersionConflictError.new(response)
    when 422
      ParameterValidationError.new(response)
    when 428
      PreconditionRequiredError.new(response)
    when 500
      ApiError.new(response)
    else
      Error.new(response)
    end
  end
end

Instance Method Details

#class_nameObject



26
27
28
# File 'lib/conekta/error.rb', line 26

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