Step 7: handle errors properly
Step 7 of 8
Say something useful for every kind of failure.
A real product must say something useful when things go wrong. Every SDK has a small set of error types you can tell apart. Branch on the kind, never on the message text.
| Situation | Error | What the user should hear |
|---|---|---|
| Typo or out-of-range value | invalid request (raised locally, before sending, free) | "Check your input: ..." |
| Wrong, revoked or expired key | authentication | "Your key was refused." |
| Balance used up | quota exceeded, never retried | "Out of plumes." |
| Too many requests | rate limit, has a retry delay | "Try again in N seconds." |
| No network | connection / timeout | "Could not reach the API." |
| Anything else | status error with status, code, request_id | "Quote request req_... to support." |
from falcore import (APIConnectionError, APIStatusError, AuthenticationError,
InvalidRequestError, QuotaExceededError, RateLimitError)
try:
build_kit(...)
except InvalidRequestError as e: print("Check your input:", e.message)
except AuthenticationError as e: print("Your key was refused:", e.code)
except QuotaExceededError as e: print("Out of plumes:", e.details)
except RateLimitError as e: print("Try again in", e.retry_after, "seconds")
except APIConnectionError: print("Could not reach the API.")
except APIStatusError as e: print("API said", e.status, e.code, "request", e.request_id)You do not retry yourself. The SDK already retries connection errors, 429 and 5xx with backoff (two retries by default) and uses an idempotency key so a retry can never create a second job or a second charge. Out-of-plumes is never retried.
Checkpoint (M4): you have seen each error message by running against a failing server (a wrong key is the easiest: set FALCORE_API_KEY=wrong).