Error Handling with Mach SDK
Properly handling errors in your Mach SDK integration is crucial for building robust and user-friendly applications. This guide covers common errors you might encounter and best practices for handling them.Error Types
The Mach SDK throws several types of errors that you can handle specifically:Common Error Codes
Here are some common error codes you might encounter when using the Mach SDK:| Error Code | Description | Suggested Handling |
|---|---|---|
NETWORK_ERROR | Connection to API or blockchain failed | Retry with exponential backoff |
INSUFFICIENT_FUNDS | User has insufficient funds | Prompt user to add funds |
USER_REJECTED | User rejected the transaction | Inform user and allow retry |
PRICE_IMPACT_TOO_HIGH | Price impact exceeds safety threshold | Warn user and request confirmation |
SLIPPAGE_EXCEEDED | Slippage tolerance was exceeded | Inform user and suggest higher slippage |
ORDER_NOT_FOUND | Referenced order doesn’t exist | Refresh order list |
INVALID_PARAMETERS | Invalid input parameters | Validate inputs before submission |
WALLET_NOT_CONNECTED | No wallet is connected | Prompt user to connect wallet |
UNSUPPORTED_CHAIN | Operation not supported on current chain | Prompt user to switch networks |
TOKEN_NOT_SUPPORTED | Token not supported for operation | Show list of supported tokens |
Retry Strategy
For transient errors like network issues, implement a retry strategy:User-Friendly Error Messages
Convert technical errors into user-friendly messages:Error Boundary Component (React)
If you’re using React, consider creating an error boundary:Logging and Monitoring
Implement comprehensive logging for production applications:Next Steps
Now that you understand how to handle errors in the Mach SDK, you might want to explore:- SDK Installation - Ensure you have the proper setup
- Cross-Chain Swaps - Implement cross-chain swaps with proper error handling