Skip to content

feat: typed errors, configurable retry, auto-pagination, status constants - #141

Merged
Diego Barajas (barajas-d) merged 15 commits into
masterfrom
feature/ergonomia-sdk
Aug 4, 2026
Merged

feat: typed errors, configurable retry, auto-pagination, status constants#141
Diego Barajas (barajas-d) merged 15 commits into
masterfrom
feature/ergonomia-sdk

Conversation

@barajas-d

Copy link
Copy Markdown
Contributor

Summary

Implements 4 ergonomics features + Feature E documentation improvements:

  • Feature D (Typed errors): MercadoPagoError(Exception) base + 12 subtypes per HTTP status. MPResponse(dict) wrapper with raise_for_status() — backward-compatible with result["status"]. Authorization header never stored in errors (CWE-209).
  • Feature B (Retry): RequestOptions gains initial_delay, max_delay, jitter (secrets.randbelow — never random), retry_on, on_retry. Silent JSON parse failure now raises MPServerError instead of print() + None.
  • Feature A (Pagination): search_auto_paging_iter() lazy generator added to: payment, customer, merchant_order, preapproval, plan, order, preference.
  • Feature E (OpenAPI + devsite): Status enum constants (PaymentStatus, OrderStatus, etc.) importable from mercadopago root. Error string constants (MPOrderErrors, MPPaymentErrors). DeprecationWarning when notification_url is passed to payment.create() or preference.create(). x-idempotency-key validated to 1–64 chars. config/defaults.py with DEFAULT_TIMEOUT_SECONDS, DEFAULT_MAX_RETRIES, DEFAULT_RETRY_ON.

Backward compatibility

  • result["status"] still works — MPResponse is a dict subclass
  • except MercadoPagoError catches all subtypes
  • 72 unit tests + 16 webhook tests passing

Diego Barajas (barajas-d) and others added 15 commits August 3, 2026 08:33
…13..018 + 046..049)

Feature D (errors): MercadoPagoError base + 11 typed subtypes (MP*Error).
MPResponse(dict) wrapper with raise_for_status(), is_success, error_message.
build_error() factory maps HTTP status codes to subtypes. Authorization header
not stored in responses (CWE-209 compliant by design — Python MPResponse holds
only response body, never request headers).

Feature E (delta): MPPaymentError/MPValidationError/MPResourceLockedError/MPDependencyError
(TASK-046). MPOrderErrors/MPPaymentErrors error string constants (TASK-046).
PaymentStatus/OrderStatus/PreapprovalStatus/MerchantOrderStatus/RefundStatus enums (TASK-047).
DeprecationWarning for notification_url in payment.create() and preference.create() (TASK-047).
x-idempotency-key 1-64 chars validation (TASK-047). Webhook docstring (TASK-047).
config/defaults.py module with DEFAULT_TIMEOUT_SECONDS=60.0, DEFAULT_MAX_RETRIES=3 (TASK-049).
initial_delay=None fix in RequestOptions (TASK-049).

Feature B (retry): RequestOptions gains initial_delay, max_delay, jitter, retry_on, on_retry.
Per-request retry_on propagated to urllib3.Retry in HttpClient. Silent JSON parse failure
now raises MPServerError instead of silent None (TASK-013).

Feature A (pagination): search_auto_paging_iter() lazy generator in pagination/iterator.py.
Added to 7 resources: payment, customer, order, preference, merchant_order, preapproval, plan.

72 unit tests passing. 16 webhook tests unchanged.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
… totals

Orders search returns results under 'data' key (not 'results') and paging
values as strings ('181') instead of integers. Iterator now checks all three
keys (results, data, elements) and Paging.from_dict() casts values to int.

Fixes search_auto_paging_iter() returning 0 items for order.search().
@barajas-d
Diego Barajas (barajas-d) merged commit eb081d2 into master Aug 4, 2026
3 checks passed
@barajas-d
Diego Barajas (barajas-d) deleted the feature/ergonomia-sdk branch August 4, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants