{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/zh/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"9. 异常处理建议（Exception Handling）","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"9-异常处理建议exception-handling","__idx":0},"children":["9. 异常处理建议（Exception Handling）"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"def handle_payment_with_retry(order_id, amount):\n    try:\n        payment = client.create_payment(order_id, \"TTRON\", \"USDT\")\n    except requests.HTTPError as exc:\n        error = exc.response.json()\n        code = error.get(\"code\")\n\n        if code == 40906:\n            # Order expired, create new order\n            order = client.create_order(amount)\n            payment = client.create_payment(order[\"order_id\"], \"TTRON\", \"USDT\")\n        elif code == 40903:\n            # Payment already exists, get existing payment\n            payments = client.request(\"GET\", f\"/v1/acquiring/payment/list?order_id={order_id}\")\n            payment = payments[\"list\"][0]\n        elif code == 40904:\n            # Temporary error, retry after delay\n            time.sleep(30)\n            payment = client.create_payment(order_id, \"TTRON\", \"USDT\")\n        elif code == 40007:\n            # Unsupported currency\n            currencies = client.get_currencies()\n            raise UnsupportedCurrency(currencies)\n        else:\n            raise\n    return payment\n","lang":"python"},"children":[]}]},"headings":[{"value":"9. 异常处理建议（Exception Handling）","id":"9-异常处理建议exception-handling","depth":2}],"frontmatter":{"seo":{"title":"9. 异常处理建议（Exception Handling）"}},"lastModified":"2026-06-12T06:47:16.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/zh/docs/en/9-error-handling","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}