Error Handling

TCG Price Lookup API के HTTP status codes, error response format और उन्हें handle करने का तरीका।


Error Response Format

सभी errors एक consistent JSON format return करते हैं:

{
  "error": {
    "code": "error_code",
    "message": "human-readable error description",
    "details": {}
  }
}

HTTP Status Codes

CodeDescription
200Success
400Bad Request (invalid parameters)
401Unauthorized (invalid या missing API key)
403Forbidden (plan access restriction)
404Not Found (card या resource exist नहीं करता)
429Too Many Requests (rate limit exceeded)
500Server Error

Common Errors और Solutions

401 Unauthorized

{ "error": { "code": "unauthorized", "message": "Invalid or missing API key" } }

Solution: API key verify करें। Check करें कि X-API-Key header सही set है।

429 Too Many Requests

{ "error": { "code": "rate_limit_exceeded", "message": "Daily limit reached" } }

Response में Retry-After header होता है जो next request तक seconds बताता है:

Retry-After: 3600
X-RateLimit-Limit: 200
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1704067200

Solution: Retry-After header respect करें। Daily limits UTC midnight पर reset होते हैं। अधिक requests चाहिए तो plan upgrade करें।

403 Forbidden

{ "error": { "code": "feature_not_available", "message": "Price history requires Trader plan" } }

Solution: Price history, graded prices, batch search जैसी features के लिए higher plan की जरूरत है।

SDKs में Error Handling

// JavaScript
try {
  const card = await tcg.cards.get('pokemon-base1-4');
} catch (error) {
  if (error.status === 429) {
    // Rate limit: wait करने का time check करें
    const retryAfter = error.headers['retry-after'];
    console.log(`Rate limited. ${retryAfter} सेकंड बाद retry करें`);
  } else if (error.status === 401) {
    console.error('API key invalid है');
  }
}
# Python
from tcglookup import TCGLookup, RateLimitError, AuthError

try:
    results = tcg.cards.search(name="charizard", game="pokemon")
except RateLimitError as e:
    print(f"Rate limited. {e.retry_after} सेकंड बाद retry करें")
except AuthError:
    print("API key invalid है")