Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Error
try { await sdk.shield({ tokenAddress, amount }); } catch (error) { console.log(error.message); // e.g., "Insufficient balance" }
"Not connected"
"Not authenticated"
"Invalid amount"
"Insufficient balance"
"Invalid privacy address"
"Chain mismatch"
"Network error: ..."
try { const result = await sdk.shield({ tokenAddress, amount }); } catch (error) { if (error.message.includes('Not authenticated')) { // User needs to log in } else if (error.message.includes('Insufficient balance')) { // Not enough tokens } else if (error.message.includes('Network error')) { // Backend unreachable — retry } else if (error.message.includes('Invalid amount')) { // Bad input } else { console.log('Unexpected error:', error.message); } }
async function withRetry<T>( operation: () => Promise<T>, maxRetries: number = 3 ): Promise<T> { for (let attempt = 1; attempt <= maxRetries; attempt++) { try { return await operation(); } catch (error) { if (error.message.includes('Network error') && attempt < maxRetries) { await new Promise((r) => setTimeout(r, 1000 * attempt)); continue; } throw error; } } throw new Error('Unreachable'); } // Usage const balance = await withRetry(() => sdk.getBalance(tokenAddress));
function userMessage(error: Error): string { const msg = error.message; if (msg.includes('Not connected')) return 'Please connect your wallet'; if (msg.includes('Not authenticated')) return 'Please log in first'; if (msg.includes('Insufficient balance')) return 'Not enough balance'; if (msg.includes('Invalid privacy address')) return 'Invalid recipient address'; if (msg.includes('Invalid amount')) return 'Invalid amount'; if (msg.includes('Chain mismatch')) return 'Please switch to the correct network'; if (msg.includes('Network error')) return 'Network error. Please try again.'; return 'Something went wrong. Please try again.'; }
try { await sdk.shield({ tokenAddress, amount }); } catch (error) { console.error('Deposit failed:', error.message); showAlert(userMessage(error)); }
try { await sdk.shield({ tokenAddress, amount }); } catch (error) { console.error('[PrivacyBoost]', error.message); showAlert(userMessage(error)); }