錯誤處理

列出 Boring API 的所有錯誤代碼、訊息與排錯建議。

回應格式

所有錯誤都會以 JSON 回傳:

{
  "success": false,
  "error": "ErrorCode",
  "message": "Human-readable error description"
}

常見 HTTP 狀態碼:

驗證相關錯誤

InvalidApiKey

Unauthorized

帳號相關錯誤

InvalidAccountId

AccountDisabled

TokenExpired

InvalidToken

請求格式錯誤

InvalidRequest

MissingParameter

InvalidPlatform

InvalidTextFormat

媒體相關錯誤

MediaDownloadFailed

InvalidMediaType

InvalidMediaUrl

MediaTooLarge

MediaRequired

InvalidCarouselSize

文字限制

TextRequired

TextTooLong

平台處理錯誤

PublishingFailed

VideoProcessingFailed

CarouselCreationFailed

速率與權限

RateLimitExceeded

InsufficientPermissions

系統錯誤

InternalServerError

ServiceUnavailable

Timeout

錯誤處理最佳實務

1. 檢查 success

result = publish_post(...)
if not result.get("success"):
    handle_error(result)

2. 實作重試

def should_retry(error_code):
    return error_code in ["RateLimitExceeded", "ServiceUnavailable", "Timeout"]

依錯誤類型決定是否重試並採用指數回退。

3. 紀錄所有錯誤

logger.error(f"API Error: {error_code} - {message}")

遇到 TokenExpiredInsufficientPermissions 等高風險錯誤時請通知維運。

4. 提供友善訊息

ERROR_MESSAGES = {
    "InvalidApiKey": "您的 API Key 無效,請到 Settings 重新產生。",
    "TokenExpired": "帳號權杖已過期,請重新連結帳號。",
    "MediaDownloadFailed": "無法下載媒體,請檢查 URL 是否可公開存取。",
    "RateLimitExceeded": "發佈過於頻繁,請稍後再試。"
}

5. 監控錯誤率

統計錯誤次數,當相同錯誤在短時間內頻繁出現時發送警示。

除錯技巧

Enable Verbose Logging

import logging
logging.basicConfig(level=logging.DEBUG)

Inspect Full Response

print(response.status_code, response.headers, response.text)

Test Media URLs

curl -I https://example.com/image.jpg

Validate JSON

json.loads(request_body)

需要更多協助?

  1. 先比對本文件的錯誤說明
  2. 檢查對應平台指南
  3. 參考範例程式碼
  4. 以最小案例重現問題
  5. 確認外部平台是否故障
  6. 若仍無解,請附上錯誤代碼與細節聯絡客服

下一步