錯誤與限流
錯誤格式
json
{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is missing, invalid, revoked or expired.",
"param": null,
"request_id": "req_..."
}
}| 欄位 | 型別 | 說明 |
|---|---|---|
type | string | 錯誤類型 |
code | string | 錯誤代碼,見錯誤代碼 |
message | string | 英文說明 |
param | string 或 null | 出錯的參數名,只在 parameter_invalid 時可能有值 |
request_id | string | 這次請求的編號,與回應標頭 X-Request-Id 相同 |
錯誤代碼
| 狀態碼 | type | code | 情況 |
|---|---|---|---|
| 400 | invalid_request | parameter_invalid | 查詢參數不接受或值不合法,見〈分頁與篩選〉 |
| 401 | authentication_error | invalid_api_key | 沒帶金鑰,或金鑰無效、已撤銷、已到期 |
| 401 | authentication_error | api_key_exposed | 金鑰出現在網址,或 Authorization、Cookie、Proxy-Authorization 以外的標頭,已撤銷 |
| 403 | permission_error | insufficient_permission | 金鑰沒有這個端點需要的權限 |
| 403 | permission_error | merchant_inactive | 商家帳號已停用 |
| 403 | permission_error | ip_not_allowed | 請求的來源位址不在金鑰允許的來源位址內 |
| 404 | invalid_request | resource_missing | 路徑不存在,或資源不存在、不屬於這家店 |
| 405 | invalid_request | method_not_allowed | 這個路徑不接受這個 HTTP 方法 |
| 429 | rate_limit_error | rate_limited | 超過限流 |
| 500 | api_error | internal_error | 伺服器錯誤 |
| 503 | api_error | service_unavailable | 服務暫時無法使用,可稍後重試 |
401 回應帶 WWW-Authenticate: Bearer 標頭。
請求編號
回應帶 X-Request-Id 標頭,格式是 req_ 加上 24 個英數字。錯誤回應的 request_id 是同一個值。
限流
- 每把金鑰分開計算;沒帶金鑰、金鑰無效,或來源位址不在金鑰允許的來源位址內的請求依來源 IP 計算。
- 回應帶
X-RateLimit-Limit(限額)、X-RateLimit-Remaining(剩餘次數)與X-RateLimit-Reset(限額重新計算的時間,UTC epoch 秒)。 - 超過限額時回 429
rate_limited,並帶Retry-After標頭(秒)。等待該秒數後再重試。