You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: propagate structured error classes across payment module
Introduce ValidationError and PaymentError classes and apply them
consistently across the entire payment module, replacing raw
throw new Error() calls with structured, actionable errors.
Changes:
- Add sdkErrors.ts with ValidationError and PaymentError classes
- Replace 18 raw Error throws across 10 payment files:
- validation.ts: ValidationError with field metadata
- sendUserOpAndWait.ts: PaymentError with error codes
- validateUSDCBasePermission.ts: ValidationError for chain/token
- getPaymentStatus.ts: PaymentError for RPC and transfer errors
- getExistingSmartWalletOrThrow.ts: PaymentError for wallet lookup
- sdkManager.ts: PaymentError for response format issues
- subscribe.ts: ValidationError + PaymentError
- createCdpClientOrThrow.ts: PaymentError for CDP init
- prepareCharge.ts / prepareRevoke.ts: PaymentError
- getSubscriptionStatus.ts: reuse validateUSDCBasePermission()
- getOrCreateSubscriptionOwnerWallet.ts: PaymentError
- Export both error classes from public API entry points
- Refactor getSubscriptionStatus to reuse validateUSDCBasePermission
instead of duplicating validation logic inline
- Update all affected tests to match new error messages
Developers can now use instanceof checks for programmatic error
handling:
import { PaymentError, ValidationError } from '@base-org/account';
try { await pay(...) } catch (e) {
if (e instanceof ValidationError) { /* fix input */ }
if (e instanceof PaymentError) { /* retry or report */ }
}
Addresses #231
`Failed to initialize CDP client for subscription owner wallet. ${errorMessage}\n\nPlease ensure you have set the required CDP credentials either:\n1. As environment variables: CDP_API_KEY_ID, CDP_API_KEY_SECRET, CDP_WALLET_SECRET\n2. As function parameters: cdpApiKeyId, cdpApiKeySecret, cdpWalletSecret\n\nYou can get these credentials from https://portal.cdp.coinbase.com/projects/api-keys`
83
+
thrownewPaymentError(
84
+
`Failed to initialize CDP client for subscription owner wallet. ${errorMessage}\n\nPlease ensure you have set the required CDP credentials either:\n1. As environment variables: CDP_API_KEY_ID, CDP_API_KEY_SECRET, CDP_WALLET_SECRET\n2. As function parameters: cdpApiKeyId, cdpApiKeySecret, cdpWalletSecret\n\nYou can get these credentials from https://portal.cdp.coinbase.com/projects/api-keys`,
85
+
'CDP_INIT_FAILED',
86
+
false
83
87
);
84
88
}
85
89
@@ -106,10 +110,16 @@ export async function getOrCreateSubscriptionOwnerWallet(
106
110
eoaAddress: eoaAccount.address,// Include EOA address for reference
107
111
};
108
112
}catch(error){
113
+
// If the error is already our custom error, re-throw it
0 commit comments