Error Handling
Both Sardis SDKs (Python and TypeScript) provide comprehensive error handling with standardized error codes, detailed error information, and type-safe error handling patterns.Error Hierarchy
Python SDK
All errors inherit fromSardisError:
TypeScript SDK
All errors extendSardisError:
Error Codes
Both SDKs use standardized error codes in the formatSARDIS_XXXX:
General Errors (1000-1099)
SARDIS_1000- Unknown errorSARDIS_1001- Internal errorSARDIS_1002- Configuration errorSARDIS_1003- Initialization error
Authentication Errors (1100-1199)
SARDIS_1100- Authentication errorSARDIS_1101- Invalid API keySARDIS_1102- Expired API keySARDIS_1103- Insufficient permissionsSARDIS_1104- ForbiddenSARDIS_2004- Token refresh failed (TypeScript)
Validation Errors (1200-1299)
SARDIS_1200- Validation errorSARDIS_1201- Invalid fieldSARDIS_1202- Missing required fieldSARDIS_1203- Invalid formatSARDIS_1204- Value out of rangeSARDIS_5004- Invalid chainSARDIS_5005- Invalid tokenSARDIS_5006- Invalid address
Resource Errors (1300-1399)
SARDIS_1300- Resource not foundSARDIS_1301- Agent not foundSARDIS_1302- Wallet not foundSARDIS_1303- Payment not foundSARDIS_1304- Hold not found
Payment Errors (1400-1499)
SARDIS_1400- Insufficient balanceSARDIS_1401- Payment failedSARDIS_1402- Payment declinedSARDIS_1403- Invalid amountSARDIS_1408- Hold expiredSARDIS_1409- Hold already capturedSARDIS_1410- Hold already voidedSARDIS_6001- Spending limit exceededSARDIS_6002- Policy violation
Rate Limiting (1500-1599)
SARDIS_1500- Rate limit exceededSARDIS_1502- Too many requests
Network Errors (1600-1699)
SARDIS_1600- Network errorSARDIS_1601- Connection errorSARDIS_1602- Timeout errorSARDIS_1604- SSL error
Blockchain Errors (1800-1899)
SARDIS_1800- Blockchain errorSARDIS_1801- Transaction failedSARDIS_1802- Gas estimation failedSARDIS_1806- Chain not supported
Compliance Errors (1900-1999)
SARDIS_1900- Compliance errorSARDIS_1901- KYC requiredSARDIS_1902- Sanctions check failedSARDIS_1904- Policy violation
Basic Error Handling
Python
TypeScript
Specific Error Types
Authentication Errors
Rate Limit Errors
Network Errors
Validation Errors
Payment Errors
Hold Errors
Error Inspection
Python
TypeScript
Retry Logic
Python with Manual Retry
Python with Built-in Retry
TypeScript with Manual Retry
TypeScript with Built-in Retry
Error Logging
Python
TypeScript
Best Practices
-
Always catch specific errors first - Handle specific error types before catching the base
SardisError -
Check if errors are retryable - Use the
retryableproperty to determine if an operation can be retried -
Log request IDs - Include
request_idin logs for support requests - Use error codes for programmatic handling - Don’t rely on error messages, use error codes
- Implement exponential backoff - For retryable errors, use exponential backoff with jitter
- Monitor error rates - Track error rates by type and code in your monitoring system
-
Handle rate limits gracefully - Respect
retry_afterheaders for rate limit errors - Provide user feedback - Convert technical errors to user-friendly messages
See Also
- Python Reference - Complete Python API reference
- TypeScript Reference - Complete TypeScript API reference
- Async Patterns - Async/await usage patterns