diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2023-05-11 18:04:01 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2023-06-12 14:31:04 +0200 |
| commit | 2b7106e417b62b86c22e8c8a3af487424d60c347 (patch) | |
| tree | 7fed61c4ad317df1f255d2c982970578fa0e134b /gui/src/renderer/components | |
| parent | 601109ac7845bf603e4b2d17bb72f30401706b71 (diff) | |
| download | mullvadvpn-2b7106e417b62b86c22e8c8a3af487424d60c347.tar.xz mullvadvpn-2b7106e417b62b86c22e8c8a3af487424d60c347.zip | |
Replace thrown error in account data fetch with typed values
Diffstat (limited to 'gui/src/renderer/components')
| -rw-r--r-- | gui/src/renderer/components/Login.tsx | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/gui/src/renderer/components/Login.tsx b/gui/src/renderer/components/Login.tsx index 4219c0572f..07d4814f1b 100644 --- a/gui/src/renderer/components/Login.tsx +++ b/gui/src/renderer/components/Login.tsx @@ -2,7 +2,7 @@ import React, { useCallback } from 'react'; import { sprintf } from 'sprintf-js'; import { colors } from '../../config.json'; -import { AccountToken } from '../../shared/daemon-rpc-types'; +import { AccountDataError, AccountToken } from '../../shared/daemon-rpc-types'; import { messages } from '../../shared/gettext'; import { useAppContext } from '../context'; import { formatAccountToken } from '../lib/account'; @@ -180,7 +180,7 @@ export default class Login extends React.Component<IProps, IState> { switch (this.props.loginState.type) { case 'failed': return this.props.loginState.method === 'existing_account' - ? this.props.loginState.error.message || messages.pgettext('login-view', 'Unknown error') + ? this.errorString(this.props.loginState.error) : messages.pgettext('login-view', 'Failed to create account'); case 'too many devices': return messages.pgettext('login-view', 'Too many devices'); @@ -197,6 +197,27 @@ export default class Login extends React.Component<IProps, IState> { } } + private errorString(error: AccountDataError['error']): string { + switch (error) { + case 'invalid-account': + // TRANSLATORS: Error message shown above login input when trying to login with a + // TRANSLATORS: non-existent account number. + return messages.pgettext('login-view', 'Invalid account number'); + case 'too-many-devices': + // TRANSLATORS: Error message shown above login input when trying to login to an account + // TRANSLATORS: with too many registered devices. + return messages.pgettext('login-view', 'Too many devices'); + case 'list-devices': + // TRANSLATORS: Error message shown above login input when trying to login but the app fails + // TRANSLATORS: to fetch the list of registered devices. + return messages.pgettext('login-view', 'Failed to fetch list of devices'); + case 'communication': + return 'api.mullvad.net is blocked, please check your firewall'; + default: + return messages.pgettext('login-view', 'Unknown error'); + } + } + private getStatusIcon() { const statusIconPath = this.getStatusIconPath(); return ( |
