Reliable trading applications must handle both REST API failures and WebSocket disconnections gracefully. TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/tiagosiebler/coinbase-api/llms.txt
Use this file to discover all available pages before exploring further.
coinbase-api SDK provides a consistent error model across all clients, with structured exception objects, configurable parsing behaviour, and automatic reconnection for WebSocket connections.
REST API Error Handling
Every REST method in the SDK returns aPromise. Wrap your await calls in a try/catch block to intercept failures cleanly.
Always use
JSON.stringify(e) when logging SDK errors. The error object is a structured plain object — not an Error instance — so console.error(e) alone may not surface all fields.The Error Object Shape
When a REST request fails, the SDK throws a structured object with the following fields:The parseExceptions Option
By default (parseExceptions: true), the SDK intercepts Axios errors and re-throws them as the structured object above. Set parseExceptions: false to receive the raw Axios error instead — useful if you have existing Axios error-handling infrastructure.
The strictParamValidation Option
When strictParamValidation: true is set, the SDK throws immediately if any parameter in a request is undefined. This is useful during development to catch missing required fields before they reach the API.
strictParamValidation defaults to false. Enable it during development and consider disabling it in production to avoid unexpected throws from optional parameters.WebSocket Error Handling
TheWebsocketClient is event-driven. Listen to the exception event to handle errors, and the close event to detect dropped connections.
Automatic Reconnection
When a WebSocket connection drops unexpectedly, the SDK handles the full reconnection cycle automatically — you do not need to resubscribe manually. The lifecycle fires these events in order:Complete Example: REST + WebSocket Error Handling
Common Error Scenarios
401 Unauthorized
401 Unauthorized
400 Bad Request
400 Bad Request
Cause: The request body or query parameters are malformed or contain invalid values.Resolution:
- Check
e.bodyfor Coinbase’s detailed error message — it often describes which field is invalid. - Enable
strictParamValidation: trueduring development to catchundefinedparameters early. - Compare your parameter names against the TypeScript type definitions in the SDK.
429 Rate Limiting
429 Rate Limiting
Cause: You have exceeded Coinbase’s rate limits for the endpoint.Resolution:
- Inspect
e.headersforRetry-AfterorX-RateLimit-Resetvalues. - Implement exponential back-off between retries.
- Consider batching requests where the API supports it.
- Coinbase rate limits are per-IP and per-key; check the Coinbase API docs for per-endpoint limits.
No Response Received
No Response Received
Cause: The request was sent but no response arrived — typically a network timeout or connectivity issue.Resolution:
- The SDK throws
e(the original Axios error) whene.responseis absent bute.requestis present. - Increase the default
timeoutvianetworkOptionsif your network is slow. - Enable
keepAlive: trueinRestClientOptionsto reuse TCP connections and reduce connection overhead.
Best Practices
- Always wrap
awaitcalls intry/catch— promises that reject without a handler cause unhandled rejection warnings in Node.js 15+ and crash in some runtimes. - Log with
JSON.stringify(e)— the error object is a plain object; string coercion produces[object Object]. - Check
e.codebefore retrying — only retry on transient errors (5xx, 429). Do not retry 401 or 400 without fixing the underlying issue. - Listen to
exceptionon everyWebsocketClient— unhandledexceptionevents will not crash the process but you will miss important diagnostic information. - Do not manually resubscribe after a reconnect — the SDK handles this automatically via its internal topic cache.