Exception: Mercadopago::MercadoPagoError

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code, response_body = nil, request_id = nil) ⇒ MercadoPagoError

Returns a new instance of MercadoPagoError.

Parameters:

  • status_code (Integer)

    HTTP status code

  • response_body (Hash) (defaults to: nil)

    parsed API error body

  • request_id (String, nil) (defaults to: nil)

    value of the x-request-id response header



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

#causesArray (readonly)

List of detailed cause hashes from the API body

Returns:

  • (Array)

    the current value of causes



14
15
16
# File 'lib/mercadopago/errors/exceptions.rb', line 14

def causes
  @causes
end

#errorString (readonly)

Machine-readable error code from the API body

Returns:

  • (String)

    the current value of error



14
15
16
# File 'lib/mercadopago/errors/exceptions.rb', line 14

def error
  @error
end

#request_idString? (readonly)

x-request-id header for support diagnostics

Returns:

  • (String, nil)

    the current value of request_id



14
15
16
# File 'lib/mercadopago/errors/exceptions.rb', line 14

def request_id
  @request_id
end

#status_codeInteger (readonly)

HTTP status code (e.g. 400, 401, 500)

Returns:

  • (Integer)

    the current value of status_code



14
15
16
# File 'lib/mercadopago/errors/exceptions.rb', line 14

def status_code
  @status_code
end