Add Detailed Error Decoding Using decodeContractError
Problem
Currently, when a smart contract call fails, the SDK throws a generic or low-level error (e.g. execution reverted), which is not helpful for debugging or UX.
Proposed Solution
- Add a
decodeContractError(error) utility.
- Use it across all contract interaction points in the SDK.
- Extract detailed messages like:
- Error reason (e.g.
Channel is already closed)
- Related
channelId, payer, or merchant if available.
- Ensure the error is structured and readable.
Benefits
- Better Developer Experience: Developers get detailed, contextual error messages which make debugging faster and more straightforward.
- Improved User Feedback: User-facing applications can show clearer error messages, like "Channel is already closed," rather than generic or unclear revert messages.
- Easier Maintenance & Logging: Structured and tagged error messages allow for easier tracking, logging, and debugging, simplifying production monitoring.
- Standardized Error Handling: The
decodeContractError utility establishes a consistent and reusable error-handling pattern across all contract interactions in the SDK.
- Extendable for Custom Errors: Future smart contract upgrades or changes can easily be supported by enhancing the error-decoding logic, especially if custom errors are used in contracts.
Example
try {
await contract.redeemChannel(channelId);
} catch (err) {
throw decodeContractError(err);
}
Add Detailed Error Decoding Using
decodeContractErrorProblem
Currently, when a smart contract call fails, the SDK throws a generic or low-level error (e.g.
execution reverted), which is not helpful for debugging or UX.Proposed Solution
decodeContractError(error)utility.Channel is already closed)channelId,payer, ormerchantif available.Benefits
decodeContractErrorutility establishes a consistent and reusable error-handling pattern across all contract interactions in the SDK.Example