Errors and retries
About 848 words
v1 draft
This page is part of the draft v1 integration contract; details may change along with the integration checklist, so rely on the official checklist published in the portal.
The result is determined by the integer code in the response envelope: 0 means success, any non-0 value means failure. Never branch your code on the HTTP status code or the msg text — an HTTP 200 response can still carry a non-0 code.
{ "id": "…", "cmd": "post_order", "code": 2004, "msg": "账户可用余额不足", "data": null, "stamp": 1795000001 }Error code ranges
| Code range | Meaning | Handling |
|---|---|---|
0 | Success | — |
1xxx | The request itself is invalid: parameters, authentication, permissions, protocol version | Do not retry; fix it per msg and resubmit |
2xxx | Business rejection: balance, goods status, order status | Do not retry; correct the business condition or place a new order |
3xxx | Conflict or duplicate: idempotency key conflict, duplicate ticket | Do not retry; verify the original result first |
4xxx | Temporary failure: rate limiting, dependency temporarily unavailable | Retry with exponential backoff |
9xxx | Indeterminate result | Verify first; do not resend blindly |
The integration checklist is authoritative
The ranges above are the integration contract; the specific error codes are defined in the integration checklist issued when your account is opened. Treat any unlisted non-0 code as 1xxx and do not retry automatically.
Common error codes
| code | Meaning | Action |
|---|---|---|
1001 | Invalid parameter | Fix the request per msg |
1002 | Authentication failed (signature, timestamp, or key) | Check the string to sign and the system clock |
1003 | No permission for this endpoint | Grant the corresponding permission to the shop in the portal |
1004 | Unsupported protocol version | Upgrade to a supported version |
2001 | SKU does not exist or is delisted | Refresh the goods catalog |
2002 | Goods suspended from sale | Stop selling this SKU |
2003 | Quantity does not satisfy the minimum, maximum, or step | Adjust per min_qty / max_qty / per in the goods list |
2004 | Insufficient available balance | Top up or reduce the quantity |
2005 | Order not yet fulfilled | Wait for fulfillment to complete before acting |
2006 | Order cannot be cancelled (already fulfilled) | Use after-sales |
2007 | Order is final | Do not repeat the operation |
2008 | Order does not exist or does not belong to this shop | Check the order number and the shop |
2009 | Order line does not exist | Verify the actual line numbers of the order |
2010 | Delivery reference expired | Query the order deliverables again |
3002 | Idempotency key conflict (same key, different content) | Check your business reference number generation |
3003 | Duplicate ticket | Wait for the existing ticket to be handled |
4001 | Rate limit triggered | Back off per retry_after |
4002 | Service temporarily unavailable | Back off and retry |
9001 | Indeterminate result | Verify with a query endpoint; do not resend |
HTTP status mapping
| HTTP | Description |
|---|---|
| 200 | The business result is in code: 0 succeeds, non-0 fails |
| 400 / 422 | Invalid request; code is usually 1xxx or 2xxx |
| 401 / 403 | Authentication or permission issue; code is usually 1002 / 1003 |
| 429 | Rate limit exceeded; code is 4001; back off per Retry-After |
| 500 / 502 / 503 | Platform-side error; check the response body code first, and treat a missing body as 4002 |
Retry strategy
code = 0 → 成功,结束
1xxx / 2xxx / 3xxx → 不重试,修正或查证
4xxx → 退避重试(1s、2s、4s、8s…,最多 5 次),同 id 同内容
9xxx → 不重发;用查询接口确认原请求结果When the response header or body provides retry_after (seconds), wait that long first.
Why 9xxx must not be resent directly
Placing an order is a command with financial side effects. A timeout may mean the order was already accepted on the platform side, and resending with a new id can create duplicate orders and duplicate charges. The correct approach:
- Query with
get_ordersbytrace_id(ororder_no/order_id). - If the order exists, continue the flow based on its current status.
- If it is not found and still missing after waiting a while, retry once with the original
id.
Idempotency
| Command | Idempotency key | Description |
|---|---|---|
post_order | req_id (unique per shop) | Same key and same content returns the original order; same key with different content returns 3002 |
req_cancel | order_no | Repeated cancellation of the same order is idempotent |
open_ticket | id | The same message ID does not create a second ticket |
Idempotency records cover the order and after-sales lifecycle for at least 30 days and do not disappear when request caches expire.
Recommended implementation
- Map
codeinto four classes: success / retryable / non-retryable / needs verification (judging by the thousands digit is enough). - On the order path, compensate
9xxxwith a query; never resend directly with a newid. - Log the
id,req_id,code, andstampof every request to simplify reconciliation with the platform. - Alert only on persistent
4xxxand a large volume of9xxx, so that a single network blip does not page the on-call engineer.