Skip to content

Commit 338df7e

Browse files
authored
Merge pull request #525 from chalabi2/chalabi/add-error-handling-back
fix: add back error handling in web3auth utils
2 parents bec767b + d147c8f commit 338df7e

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

wallets/web3auth/src/extension/utils.ts

+21-7
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const listenOnce = (
4949
try {
5050
remove = await callback(data);
5151
} catch (error) {
52+
console.error(error);
5253
remove = true;
5354
}
5455

@@ -57,7 +58,6 @@ export const listenOnce = (
5758
removeEventListener?.call(worker, 'message', listener as any);
5859
}
5960
};
60-
6161
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6262
addEventListener?.call(worker, 'message', listener as any);
6363
};
@@ -126,6 +126,7 @@ export const connectClientAndProvider = async (
126126
chainId: 'other',
127127
rpcTarget: 'other',
128128
displayName: 'other',
129+
blockExplorer: 'other',
129130
ticker: 'other',
130131
tickerName: 'other',
131132
...options.client.chainConfig,
@@ -170,12 +171,25 @@ export const connectClientAndProvider = async (
170171

171172
let provider = client.connected ? client.provider : null;
172173
if (!client.connected && !dontAttemptLogin) {
173-
const loginHint = options.getLoginHint?.();
174-
175-
provider = await client.connectTo(WALLET_ADAPTERS.OPENLOGIN, {
176-
loginProvider: options.loginProvider,
177-
login_hint: loginHint,
178-
} as OpenloginLoginParams);
174+
try {
175+
const loginHint = options.getLoginHint?.();
176+
provider = await client.connectTo(WALLET_ADAPTERS.OPENLOGIN, {
177+
loginProvider: options.loginProvider,
178+
login_hint: loginHint,
179+
} as OpenloginLoginParams);
180+
} catch (err) {
181+
// Unnecessary error thrown during redirect, so log and ignore it.
182+
if (
183+
usingRedirect &&
184+
err instanceof Error &&
185+
err.message.includes('null')
186+
) {
187+
console.error(err);
188+
} else {
189+
// Rethrow all other relevant errors.
190+
throw err;
191+
}
192+
}
179193
}
180194

181195
if (usingRedirect) {

0 commit comments

Comments
 (0)