Exception: Recurly::Errors::APIError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/recurly/errors.rb,
lib/recurly/errors/api_errors.rb

Direct Known Subclasses

NetworkError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, response = nil, error = nil) ⇒ APIError

Returns a new instance of APIError.



46
47
48
49
50
# File 'lib/recurly/errors.rb', line 46

def initialize(message, response = nil, error = nil)
  super(message)
  @response = response
  @recurly_error = error
end

Instance Attribute Details

#recurly_errorObject

Returns the value of attribute recurly_error.



6
7
8
# File 'lib/recurly/errors.rb', line 6

def recurly_error
  @recurly_error
end

Class Method Details

.error_class(error_key) ⇒ Errors::APIError, Errors::NetworkError

Looks up an Error class by name

Examples:

Errors.error_class('BadRequestError')
#=> Errors::BadRequestError

Parameters:

Returns:



27
28
29
30
31
# File 'lib/recurly/errors.rb', line 27

def self.error_class(error_key)
  class_name = error_key.split("_").map(&:capitalize).join
  class_name += "Error" unless class_name.end_with?("Error")
  Errors.const_get(class_name)
end

.from_response(response) ⇒ Errors::APIError

When the response does not have a JSON body, this determines the appropriate Error class based on the response code. This may occur when a load balancer returns an error before it reaches Recurly's API.

Parameters:

Returns:



38
39
40
41
42
43
44
# File 'lib/recurly/errors.rb', line 38

def self.from_response(response)
  if error_map.has_key?(response.code)
    Recurly::Errors.const_get(error_map[response.code])
  else
    Recurly::Errors::APIError
  end
end

Instance Method Details

#get_responseObject



56
57
58
# File 'lib/recurly/errors.rb', line 56

def get_response
  @response
end

#status_codeObject



52
53
54
# File 'lib/recurly/errors.rb', line 52

def status_code
  @response.status
end