mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-18 21:40:41 -04:00
Add try catch for incorrect status login call (#601)
This commit is contained in:
committed by
Leendert de Borst
parent
5c010cd873
commit
65d1ca1564
@@ -58,7 +58,8 @@ const App: React.FC = () => {
|
||||
useEffect(() => {
|
||||
if (authContext.globalMessage) {
|
||||
setMessage(authContext.globalMessage);
|
||||
authContext.clearGlobalMessage();
|
||||
} else {
|
||||
setMessage(null);
|
||||
}
|
||||
}, [authContext, authContext.globalMessage]);
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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<StatusResponse> {
|
||||
return await this.get<StatusResponse>('Auth/status');
|
||||
try {
|
||||
return await this.get<StatusResponse>('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.';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user