Errors
Error Handling
The SuiPay SDK provides comprehensive error handling with specific error types for different scenarios.
Error Types
The SDK provides the following error classes:
import {
SuiPayError, // Base error class
SuiPayValidationError, // 400 - Request validation errors
SuiPayAuthenticationError, // 401 - API key issues
SuiPayRateLimitError, // 429 - Rate limiting
SuiPayServerError // 5xx - Server-side errors
} from '@suipay/api';Basic Error Handling
All SDK methods can throw errors. Use try-catch blocks to handle them:
try {
const user = await client.user.get();
console.log('User loaded successfully');
} catch (error) {
console.error('Failed to load user:', error.message);
}Specific Error Types
SuiPayValidationError (400)
Thrown when request validation fails:
SuiPayAuthenticationError (401)
Thrown when API key is invalid or missing:
SuiPayRateLimitError (429)
Thrown when rate limits are exceeded:
SuiPayServerError (5xx)
Thrown when server-side errors occur:
Comprehensive Error Handling
Handle all error types in a single try-catch block:
Best Practices
1. Implement Retry Logic
2. User-Friendly Messages
3. Error Logging
Error Handling Checklist
✅ Handle specific error types with appropriate actions ✅ Implement retry logic for transient errors ✅ Log errors with sufficient context for debugging ✅ Show user-friendly messages instead of technical errors ✅ Validate input before making API calls ✅ Test error scenarios in your application
Last updated