From 16a9a87940886620efe45ead84b12fed69a7758b Mon Sep 17 00:00:00 2001 From: Jack Greenlee Date: Mon, 14 Oct 2024 11:53:01 -0400 Subject: [PATCH] better error handling in opcode.ts -catch error that could be thrown from getTokenFromUrl -pass return value of false on either of the catch blocks -only show "proceeding with OPcode ..." if result from initByUser was true -ability to pass style through to AlertBar; wordBreak: break-all so that long OPcodes will not be forced onto one line --- www/i18n/en.json | 3 ++- www/js/components/AlertBar.tsx | 2 ++ www/js/config/opcode.ts | 20 ++++++++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/www/i18n/en.json b/www/i18n/en.json index afd4e2600..ec432d89e 100644 --- a/www/i18n/en.json +++ b/www/i18n/en.json @@ -404,7 +404,8 @@ "all-green-status": "Make sure that all status checks are green", "dont-force-kill": "Do not force kill the app", "background-restrictions": "On Samsung and Huwaei phones, make sure that background restrictions are turned off", - "close": "Close" + "close": "Close", + "proceeding-with-token": "Proceeding with OPcode: {{token}}" }, "config": { "unable-read-saved-config": "Unable to read saved config", diff --git a/www/js/components/AlertBar.tsx b/www/js/components/AlertBar.tsx index 8b1b39fcf..6302bd795 100644 --- a/www/js/components/AlertBar.tsx +++ b/www/js/components/AlertBar.tsx @@ -10,6 +10,7 @@ type AlertMessage = { msgKey?: ParseKeys<'translation'>; text?: string; duration?: number; + style?: object; }; // public static AlertManager that can add messages from a global context @@ -45,6 +46,7 @@ const AlertBar = () => { visible={true} onDismiss={onDismissSnackBar} duration={messages[0].duration} + style={messages[0].style} action={{ label: t('join.close'), onPress: onDismissSnackBar, diff --git a/www/js/config/opcode.ts b/www/js/config/opcode.ts index 63eb02c16..a5483d5c2 100644 --- a/www/js/config/opcode.ts +++ b/www/js/config/opcode.ts @@ -143,11 +143,23 @@ function getTokenFromUrl(url: string) { } export async function joinWithTokenOrUrl(tokenOrUrl: string) { - const token = tokenOrUrl.includes('://') ? getTokenFromUrl(tokenOrUrl) : tokenOrUrl; - AlertManager.addMessage({ text: i18next.t('join.proceeding-with-token', { token }) }); try { - return await initByUser({ token }); + const token = tokenOrUrl.includes('://') ? getTokenFromUrl(tokenOrUrl) : tokenOrUrl; + try { + const result = await initByUser({ token }); + if (result) { + AlertManager.addMessage({ + text: i18next.t('join.proceeding-with-token', { token }), + style: { wordBreak: 'break-all' }, + }); + } + return result; + } catch (err) { + displayError(err, 'Error logging in with token: ' + token); + return false; + } } catch (err) { - displayError(err, 'Error logging in with token'); + displayError(err, 'Error parsing token or URL: ' + tokenOrUrl); + return false; } }