Skip to content

Commit

Permalink
feat: differentiate between api errors and rpc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
samsiegart committed Dec 14, 2023
1 parent 7289e78 commit ee9964f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Errors } from '../errors.js';
/**
* @param {any} chainStorageWatcher
* @param {string} rpc
* @param {((error: unknown) => void)=} onRpcError
* @param {((error: unknown) => void)} [onRpcError]
*/
export const makeAgoricWalletConnection = async (
chainStorageWatcher,
Expand Down
15 changes: 11 additions & 4 deletions packages/web-components/src/wallet-connection/watchWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const MAX_ATTEMPTS_TO_WATCH_BANK = 2;
* @param {any} chainStorageWatcher
* @param {string} address
* @param {string} rpc
* @param {((error: unknown) => void)=} onRpcError
* @param {((error: unknown) => void)} [onRpcError]
*/
export const watchWallet = (chainStorageWatcher, address, rpc, onRpcError) => {
const pursesNotifierKit = makeNotifierKit(
Expand Down Expand Up @@ -140,7 +140,10 @@ export const watchWallet = (chainStorageWatcher, address, rpc, onRpcError) => {
} catch (e) {
console.error('Error querying bank balances for address', address);
if (attempts >= MAX_ATTEMPTS_TO_WATCH_BANK) {
onRpcError && onRpcError(e);
onRpcError &&
onRpcError(
new Error(`RPC error${e.toString && ` - ${e.toString()}`}`),
);
} else {
setTimeout(() => watchBank(attempts + 1), RETRY_INTERVAL_MS);
return;
Expand Down Expand Up @@ -222,7 +225,10 @@ export const watchWallet = (chainStorageWatcher, address, rpc, onRpcError) => {
);
} catch (e) {
console.error('Error getting boardAux for brands', brands, e);
onRpcError && onRpcError(e);
onRpcError &&
onRpcError(
new Error(`API error${e.toString && ` - ${e.toString()}`}`),
);
}
}

Expand Down Expand Up @@ -256,7 +262,8 @@ export const watchWallet = (chainStorageWatcher, address, rpc, onRpcError) => {
try {
await watch();
} catch (e) {
onRpcError && onRpcError(e);
onRpcError &&
onRpcError(new Error(`RPC error${e.toString && ` - ${e.toString()}`}`));
}
};

Expand Down

0 comments on commit ee9964f

Please sign in to comment.