From 65d1ca15642019b61e9fcce01c738aa4d08ff085 Mon Sep 17 00:00:00 2001 From: Leendert de Borst Date: Mon, 24 Feb 2025 21:01:16 +0100 Subject: [PATCH] Add try catch for incorrect status login call (#601) --- browser-extensions/chrome/src/app/App.tsx | 3 ++- .../chrome/src/app/pages/Login.tsx | 8 +++++--- .../chrome/src/shared/WebApiService.ts | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/browser-extensions/chrome/src/app/App.tsx b/browser-extensions/chrome/src/app/App.tsx index 71532b4ab..ca682ab0f 100644 --- a/browser-extensions/chrome/src/app/App.tsx +++ b/browser-extensions/chrome/src/app/App.tsx @@ -58,7 +58,8 @@ const App: React.FC = () => { useEffect(() => { if (authContext.globalMessage) { setMessage(authContext.globalMessage); - authContext.clearGlobalMessage(); + } else { + setMessage(null); } }, [authContext, authContext.globalMessage]); diff --git a/browser-extensions/chrome/src/app/pages/Login.tsx b/browser-extensions/chrome/src/app/pages/Login.tsx index cf01353c9..13391d693 100644 --- a/browser-extensions/chrome/src/app/pages/Login.tsx +++ b/browser-extensions/chrome/src/app/pages/Login.tsx @@ -60,6 +60,9 @@ const Login: React.FC = () => { try { showLoading(); + // Clear global message if set with every login attempt. + authContext.clearGlobalMessage(); + // Use the srpUtil instance instead of the imported singleton const loginResponse = await srpUtil.initiateLogin(credentials.username); @@ -127,9 +130,8 @@ const Login: React.FC = () => { // Show app. hideLoading(); - } catch (err) { - setError('Login failed. Please check your credentials and try again.'); - console.error('Login error:', err); + } catch { + setError('Could not reach AliasVault server. Please try again later or contact support if the problem persists.'); hideLoading(); } }; diff --git a/browser-extensions/chrome/src/shared/WebApiService.ts b/browser-extensions/chrome/src/shared/WebApiService.ts index e946225e0..c5dc1c173 100644 --- a/browser-extensions/chrome/src/shared/WebApiService.ts +++ b/browser-extensions/chrome/src/shared/WebApiService.ts @@ -219,13 +219,29 @@ export class WebApiService { * Calls the status endpoint to check if the auth tokens are still valid, app is supported and the vault is up to date. */ public async getStatus(): Promise { - return await this.get('Auth/status'); + try { + return await this.get('Auth/status'); + } catch { + /** + * If the status endpoint is not available, return a default status response which will trigger + * a logout and error message. + */ + return { + clientVersionSupported: true, + serverVersion: '0.0.0', + vaultRevision: 0 + }; + } } /** * Validates the status response and returns an error message if validation fails. */ public validateStatusResponse(statusResponse: StatusResponse): string | null { + if (statusResponse.serverVersion === '0.0.0') { + return 'The AliasVault server is not available. Please try again later or contact support if the problem persists.'; + } + if (!statusResponse.clientVersionSupported) { return 'This version of the AliasVault browser extension is outdated. Please update your browser extension to the latest version.'; }