feat: typed errors, configurable retry, auto-pagination, status constants - #141
Merged
Conversation
…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().
luismeli10 (luismeli10)
approved these changes
Aug 4, 2026
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements 4 ergonomics features + Feature E documentation improvements:
MercadoPagoError(Exception)base + 12 subtypes per HTTP status.MPResponse(dict)wrapper withraise_for_status()— backward-compatible withresult["status"].Authorizationheader never stored in errors (CWE-209).RequestOptionsgainsinitial_delay,max_delay,jitter(secrets.randbelow— neverrandom),retry_on,on_retry. Silent JSON parse failure now raisesMPServerErrorinstead ofprint()+None.search_auto_paging_iter()lazy generator added to:payment,customer,merchant_order,preapproval,plan,order,preference.PaymentStatus,OrderStatus, etc.) importable frommercadopagoroot. Error string constants (MPOrderErrors,MPPaymentErrors).DeprecationWarningwhennotification_urlis passed topayment.create()orpreference.create().x-idempotency-keyvalidated to 1–64 chars.config/defaults.pywithDEFAULT_TIMEOUT_SECONDS,DEFAULT_MAX_RETRIES,DEFAULT_RETRY_ON.Backward compatibility
result["status"]still works —MPResponseis adictsubclassexcept MercadoPagoErrorcatches all subtypes