diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-06-04 13:45:06 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-06-10 13:46:17 +0200 |
| commit | bfd3b02a3936451ae43867f8f3e2f986a2a2f9bc (patch) | |
| tree | 3ab241e849f8f22f5bc0a8e5af226c8b30e4552e /gui/src/renderer/lib | |
| parent | d7fdccb58e8205ae26023629873922979644bfdd (diff) | |
| download | mullvadvpn-bfd3b02a3936451ae43867f8f3e2f986a2a2f9bc.tar.xz mullvadvpn-bfd3b02a3936451ae43867f8f3e2f986a2a2f9bc.zip | |
Categorize notifications and their logic into notification definition
Diffstat (limited to 'gui/src/renderer/lib')
| -rw-r--r-- | gui/src/renderer/lib/auth-failure.ts | 81 |
1 files changed, 0 insertions, 81 deletions
diff --git a/gui/src/renderer/lib/auth-failure.ts b/gui/src/renderer/lib/auth-failure.ts deleted file mode 100644 index ead0b08a81..0000000000 --- a/gui/src/renderer/lib/auth-failure.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { messages } from '../../shared/gettext'; - -export enum AuthFailureKind { - invalidAccount, - expiredAccount, - tooManyConnections, - unknown, -} - -interface IAuthFailure { - kind: AuthFailureKind; - message: string; -} - -export function parseAuthFailure(rawFailureMessage?: string): IAuthFailure { - if (rawFailureMessage) { - const results = /^\[(\w+)\]\s*(.*)$/.exec(rawFailureMessage); - - if (results && results.length === 3) { - const kind = parseRawFailureKind(results[1]); - const message = kind === AuthFailureKind.unknown ? results[2] : messageForFailureKind(kind); - - return { - kind, - message, - }; - } else { - return { - kind: AuthFailureKind.unknown, - message: rawFailureMessage, - }; - } - } else { - return { - kind: AuthFailureKind.unknown, - message: messageForFailureKind(AuthFailureKind.unknown), - }; - } -} - -function parseRawFailureKind(failureId: string): AuthFailureKind { - // These strings should match up with mullvad-types/src/auth_failed.rs - switch (failureId) { - case 'INVALID_ACCOUNT': - return AuthFailureKind.invalidAccount; - - case 'EXPIRED_ACCOUNT': - return AuthFailureKind.expiredAccount; - - case 'TOO_MANY_CONNECTIONS': - return AuthFailureKind.tooManyConnections; - - default: - return AuthFailureKind.unknown; - } -} - -function messageForFailureKind(kind: AuthFailureKind): string { - switch (kind) { - case AuthFailureKind.invalidAccount: - return messages.pgettext( - 'auth-failure', - "You've logged in with an account number that is not valid. Please log out and try another one.", - ); - - case AuthFailureKind.expiredAccount: - return messages.pgettext( - 'auth-failure', - 'You have no more VPN time left on this account. Please log in on our website to buy more credit.', - ); - - case AuthFailureKind.tooManyConnections: - return messages.pgettext( - 'auth-failure', - 'This account has too many simultaneous connections. Disconnect another device or try connecting again shortly.', - ); - - case AuthFailureKind.unknown: - return messages.pgettext('auth-failure', 'Account authentication failed.'); - } -} |
