Skip to main content

Error Handling

This guide covers error handling in the Cadenza WebSocket API, including error response formats and error codes.

Error Response Format

When an RPC call fails, the response contains an error object:

{
"code": 22016,
"message": "Not found"
}
FieldTypeDescription
codenumberPositive error code identifying the error type
messagestringHuman-readable error message

Error Code Format

Error codes follow the format: 22XXX where:

  • 22 indicates a Usecase (business logic) error
  • XXX (three digits) represents the specific error

For example, 22016 breaks down as:

  • 22 = Usecase component
  • 016 = Not found error

Error Codes

CodeMessageDescription
22000Unknown errorGeneral business logic error.
22001Duplicate exchangeExchange connection already exists.
22002Duplicate exchange nameExchange name already in use.
22003Exchange account ID mismatchAccount ID mismatch during renewal.
22004User name already existsUsername is already taken.
22005Hash function failedFailed to generate or verify hash.
22006Invalid API keyAPI key is invalid or has insufficient permissions.
22007Webhook trigger failedFailed to trigger webhook event.
22008Encryption failedFailed to encrypt data.
22009Exchange already deletedExchange connection was already deleted.
22010Exchange already existsExchange connection already exists.
22011Exchange type not supportedExchange type is not supported.
22012Invalid exchange nameExchange name is invalid.
22013Exchange not foundExchange connection not found.
22014Lock not acquiredFailed to acquire resource lock. Retry after a short delay.
22015Invalid argumentInvalid argument for operation.
22016Not foundRequested resource not found.
22017Already existResource already exists.
22018Permission deniedInsufficient permissions for this operation.
22019Operation unsupportedOperation not supported in current context.
22020Exchange not supportedExchange is not supported.
22021Database failureDatabase operation failed.
22022Exchange timeoutExchange operation timed out.
22023UnauthorizedNot authorized for this operation.
22024No valid exchange accountNo valid exchange account found.
22025Set priority failFailed to set operation priority.
22026Unsupported route policyRouting policy not supported.
22027Prerequisite errorPrerequisite condition not met.
22028Cache not hitData not found in cache.
22029Bad requestInvalid client request.
22030Pubsub client not setPub/sub client not configured.
22031TimeoutOperation timed out.
22032Invalid execution planExecution plan is invalid.

Handling Errors

Python Example

from centrifuge import Client, RpcError

async def safe_rpc_call(client: Client, method: str, params: dict):
try:
result = await client.rpc(method, params)
return result.data
except RpcError as e:
print(f"RPC Error: code={e.code}, message={e.message}")

# Handle specific error codes
if e.code == 22016: # Not found
return None
elif e.code == 22023: # Unauthorized
raise UnauthorizedError(e.message)
else:
raise

TypeScript Example

import { Centrifuge, RpcError } from 'centrifuge'

async function safeRpcCall(client: Centrifuge, method: string, params: object) {
try {
const result = await client.rpc(method, params)
return result.data
} catch (error) {
if (error instanceof RpcError) {
console.error(`RPC Error: code=${error.code}, message=${error.message}`)

// Handle specific error codes
if (error.code === 22016) { // Not found
return null
}
}
throw error
}
}

Best Practices

  1. Always handle errors - Wrap RPC calls in try/catch blocks
  2. Log error details - Include error code and message for debugging
  3. Handle specific codes - Implement logic for expected error scenarios
  4. Retry transient errors - Errors like 22014 (lock not acquired), 22031 (timeout) may be temporary
  5. Avoid retrying permanent errors - Errors like 22016 (not found) won't resolve with retries