Stock market data infrastructure
API errors and retry behavior
Build bounded retries for stock data requests while preserving error details and separating invalid requests from temporary failures.
Documentation revised
Classify the failure
Read the HTTP status and JSON detail together. A 400 can identify an unsupported range or interval; 422 can indicate invalid query types or bounds. A 404 can mean an unresolved company, index, or document. A valid company with no stored prices can instead return an empty bars array.
401 identifies an authentication problem; 403 can identify access restrictions. Payment-enabled operations may return 402 requirements. Do not automatically authorize or submit payment just because a request received 402.
Retry only recoverable requests
For 429, honor Retry-After when supplied and pause before trying again. Use bounded exponential backoff with jitter for transient connection failures and appropriate 5xx responses. Set a per-request timeout, maximum attempts, and an overall deadline. Repeating an invalid symbol or denied access cannot repair the request.
Keep useful diagnostics
Log method, path without secrets, status, elapsed time, and a redacted error detail. Preserve an empty successful response separately from a transport failure. For mutating operations such as key rotation or completion requests, inspect current state before repeating a request whose outcome is uncertain.