Error Handling
The SDK implements comprehensive error handling through the LombardError class. All errors can be identified using the isLombardError() utility function.
Error Structure
Each error contains:
| Property | Type | Description |
|---|---|---|
code | AnyErrorCode | Machine-readable error code |
message | string | Human-readable description |
metadata | Record<string, unknown> | Additional context |
Error Categories
General Errors
| Code | Description |
|---|---|
unknown-error | An unexpected error occurred |
invalid-configuration | SDK configuration is invalid |
operation-timeout | Operation timed out |
operation-cancelled | User cancelled the operation |
Provider Errors
| Code | Description |
|---|---|
provider-missing | Required wallet provider not configured |
provider-initialization-failed | Failed to initialize wallet provider |
provider-call-failed | Wallet provider method call failed |
signer-missing | Transaction signer not available |
user-rejected | User rejected the transaction or signature |
network-mismatch | Wallet is connected to wrong network |
Validation Errors
| Code | Description |
|---|---|
invalid-address | Address format is invalid |
invalid-amount | Amount format is invalid |
amount-too-small | Amount is below minimum |
amount-too-large | Amount is above maximum |
insufficient-balance | Not enough balance for operation |
invalid-parameter | Parameter value is invalid |
missing-required-parameter | Required parameter was not provided |
invalid-chain | Chain is not supported |
invalid-state | Action is in invalid state for operation |
invalid-asset | Asset is not supported |
Contract Errors
| Code | Description |
|---|---|
contract-call-failed | Smart contract call failed |
transaction-failed | Transaction execution failed |
transaction-reverted | Transaction was reverted |
approval-failed | Token approval failed |
insufficient-allowance | Token allowance is too low |
gas-estimation-failed | Could not estimate gas |
Registry Errors
| Code | Description |
|---|---|
route-not-found | No matching route found |
invalid-route-definition | Route definition is invalid |
unsupported-chain | Chain is not supported in environment |
unsupported-asset | Asset is not supported |
incompatible-route | Route is incompatible with parameters |
environment-mismatch | Environment mismatch |
Implementation Pattern
import { isLombardError } from '@lombard.finance/sdk';
try {
await stake.authorize();
} catch (error) {
if (isLombardError(error)) {
switch (error.code) {
case 'user-rejected':
// User cancelled - show retry option
break;
case 'network-mismatch':
// Prompt user to switch networks
break;
case 'amount-too-small':
// Show minimum amount from error.metadata
break;
default:
console.error(error.code, error.message);
}
}
}The framework preserves action state across errors, allowing direct retry of failed operations without resetting the workflow.
Last updated on