Exception: Conexa::ResponseError
- Inherits:
-
ConexaError
- Object
- StandardError
- ConexaError
- Conexa::ResponseError
- Defined in:
- lib/conexa/errors.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_response ⇒ Hash
readonly
The decoded error body, when the API returned one.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#request_params ⇒ Object
readonly
Returns the value of attribute request_params.
Instance Method Summary collapse
-
#api_error_codes ⇒ Array<String>
Documented business-rule codes, e.g.
-
#api_error_messages ⇒ Array<String>
One readable line per error, whichever shape it arrived in.
-
#api_errors ⇒ Array<Hash{Symbol=>String,nil}>
The API's errors, normalised across its two shapes.
-
#initialize(request_params, error, message = nil, api_response = nil) ⇒ ResponseError
constructor
A new instance of ResponseError.
Constructor Details
#initialize(request_params, error, message = nil, api_response = nil) ⇒ ResponseError
Returns a new instance of ResponseError.
31 32 33 34 35 36 37 |
# File 'lib/conexa/errors.rb', line 31 def initialize(request_params, error, =nil, api_response=nil) @request_params, @error = request_params, error @api_response = api_response.is_a?(Hash) ? api_response : {} msg = describe_error(error) msg += " => " + if super msg end |
Instance Attribute Details
#api_response ⇒ Hash (readonly)
The decoded error body, when the API returned one.
29 30 31 |
# File 'lib/conexa/errors.rb', line 29 def api_response @api_response end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
25 26 27 |
# File 'lib/conexa/errors.rb', line 25 def error @error end |
#request_params ⇒ Object (readonly)
Returns the value of attribute request_params.
25 26 27 |
# File 'lib/conexa/errors.rb', line 25 def request_params @request_params end |
Instance Method Details
#api_error_codes ⇒ Array<String>
Documented business-rule codes, e.g. "CHARGE_11" or "CONTRACT_RECURRING_SALE_10". These are what a caller branches on — for instance to tell an already-settled charge from a real settlement failure.
62 63 64 |
# File 'lib/conexa/errors.rb', line 62 def api_error_codes api_errors.filter_map { |entry| entry[:code] } end |
#api_error_messages ⇒ Array<String>
One readable line per error, whichever shape it arrived in.
68 69 70 71 72 73 |
# File 'lib/conexa/errors.rb', line 68 def api_errors.map do |entry| label = entry[:field] || entry[:code] label ? "#{label}: #{entry[:message]}" : entry[:message] end end |
#api_errors ⇒ Array<Hash{Symbol=>String,nil}>
The API's errors, normalised across its two shapes.
Field validation answers {"field": …, "messages": [...]}; business rules
answer {"code": …, "message": …}. Consumers that only handled the first
rendered business-rule errors as blank strings — which is how
CONTRACT_RECURRING_SALE_10 stayed invisible through eight attempts.
47 48 49 50 51 52 53 54 55 |
# File 'lib/conexa/errors.rb', line 47 def api_errors Array(api_response["errors"]).filter_map do |entry| next unless entry.is_a?(Hash) { field: entry["field"], code: entry["code"], message: entry["message"] || Array(entry["messages"]).join("; ") } end end |