Error Handling
The Conto SDK provides detailed error information to help you handle failures gracefully.ContoError Class
All SDK errors extend theContoError class:
Error Codes
Authentication Errors
| Code | Status | Description | Solution |
|---|---|---|---|
AUTH_FAILED | 401 | Invalid or expired API key | Check key is correct and not revoked |
EXPIRED_KEY | 401 | Key has expired | Generate a new SDK key |
INSUFFICIENT_SCOPE | 403 | Key lacks required permission | Use key with required scope |
Payment Errors
| Code | Status | Description | Solution |
|---|---|---|---|
PAYMENT_DENIED | 403 | Payment blocked by policy | Check violations for details |
REQUIRES_APPROVAL | 202 | Needs manual approval | Wait for human approval |
INSUFFICIENT_BALANCE | 400 | Wallet has insufficient funds | Fund the wallet |
DAILY_LIMIT_EXCEEDED | 400 | Daily limit exceeded | Wait for reset or increase limit |
PER_TX_LIMIT_EXCEEDED | 400 | Amount exceeds per-tx limit | Reduce amount or increase limit |
EXPIRED | 400 | Payment request expired | Request new approval |
NOT_FOUND | 404 | Request ID not found | Check the request ID |
INVALID_STATUS | 400 | Cannot execute in current status | Check payment status |
NO_WALLET | 400 | No wallet assigned | Link a wallet to the agent |
EXTERNAL_WALLET | 400 | Cannot execute external wallet via /execute | Use /confirm with your own txHash |
POLICY_DENIED | 400 | Payment denied by policy (enriched) | Check context.nextSteps |
Validation Errors
| Code | Status | Description | Solution |
|---|---|---|---|
VALIDATION_ERROR | 400 | Invalid request body | Check request parameters |
INVALID_AMOUNT | 400 | Amount must be positive | Use a positive number |
INVALID_ADDRESS | 400 | Malformed Ethereum address | Use valid 0x address |
System Errors
| Code | Status | Description | Solution |
|---|---|---|---|
RATE_LIMITED | 429 | Too many requests | Wait and retry |
TIMEOUT | 0 | Request timeout | Retry with longer timeout |
INTERNAL_ERROR | 500 | Server error | Retry or contact support |
Handling Errors
Basic Error Handling
Handling Specific Error Codes
Enriched Error Responses
Some SDK error responses include additional context to help agents recover programmatically. These enriched errors includehint, context, and nextSteps fields.
Error Response Structure
Example: External Wallet Error
When trying to/execute a payment assigned to an external wallet:
Example: Insufficient Balance Error
Handling Enriched Errors
Using Request/Execute for Better Control
Thepay() method throws on denial. For more control, use separate request/execute:
Handling Rate Limits
When rate limited, the SDK throws withretryAfter information:
Handling Timeouts
For long-running requests, handle timeouts:Retry Strategy
With Exponential Backoff
Logging Errors
Best Practices
Always Catch Errors
Always Catch Errors
Never let payment errors crash your application:
Check Specific Error Codes
Check Specific Error Codes
Don’t just catch generic errors:
Don't Retry Payment Execution
Don't Retry Payment Execution
Be careful with retries on payment execution:
Log for Debugging
Log for Debugging
Always log error details for debugging: