Exception: Mercadopago::MercadoPagoError
- Inherits:
-
StandardError
- Object
- StandardError
- Mercadopago::MercadoPagoError
- Defined in:
- lib/mercadopago/errors/exceptions.rb
Overview
Base exception for all MercadoPago API errors.
All subtypes inherit from this class, preserving backward-compatible
rescue MercadoPagoError patterns while enabling specific handling
per HTTP status code.
Direct Known Subclasses
MPAuthenticationError, MPBadRequestError, MPConnectionError, MPDependencyError, MPForbiddenError, MPIdempotencyError, MPNotFoundError, MPPaymentError, MPRateLimitError, MPResourceLockedError, MPServerError, MPValidationError
Instance Attribute Summary collapse
-
#causes ⇒ Array
readonly
List of detailed cause hashes from the API body.
-
#error ⇒ String
readonly
Machine-readable error code from the API body.
-
#request_id ⇒ String?
readonly
x-request-id header for support diagnostics.
-
#status_code ⇒ Integer
readonly
HTTP status code (e.g. 400, 401, 500).
Instance Method Summary collapse
-
#initialize(status_code, response_body = nil, request_id = nil) ⇒ MercadoPagoError
constructor
A new instance of MercadoPagoError.
Constructor Details
#initialize(status_code, response_body = nil, request_id = nil) ⇒ MercadoPagoError
Returns a new instance of MercadoPagoError.
20 21 22 23 24 25 26 27 |
# File 'lib/mercadopago/errors/exceptions.rb', line 20 def initialize(status_code, response_body = nil, request_id = nil) body = (response_body.is_a?(Hash) ? response_body : {}) super(body['message'] || body[:message] || body['error'] || body[:error] || 'MercadoPago API error') @status_code = status_code @error = body['error'] || body[:error] || '' @causes = body['cause'] || body[:cause] || [] @request_id = request_id end |
Instance Attribute Details
#causes ⇒ Array (readonly)
List of detailed cause hashes from the API body
14 15 16 |
# File 'lib/mercadopago/errors/exceptions.rb', line 14 def causes @causes end |
#error ⇒ String (readonly)
Machine-readable error code from the API body
14 15 16 |
# File 'lib/mercadopago/errors/exceptions.rb', line 14 def error @error end |
#request_id ⇒ String? (readonly)
x-request-id header for support diagnostics
14 15 16 |
# File 'lib/mercadopago/errors/exceptions.rb', line 14 def request_id @request_id end |
#status_code ⇒ Integer (readonly)
HTTP status code (e.g. 400, 401, 500)
14 15 16 |
# File 'lib/mercadopago/errors/exceptions.rb', line 14 def status_code @status_code end |