diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2022-09-26 16:15:29 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2022-11-30 10:36:19 +0100 |
| commit | 3fd327525882bc6459ed425de67ed687c949ef3f (patch) | |
| tree | 90b137e3a24800ffd2f33d7e89e2b45700c101d8 /gui/src | |
| parent | d424bdbedeb1c8e44b693eac02d169e11b7ac92a (diff) | |
| download | mullvadvpn-3fd327525882bc6459ed425de67ed687c949ef3f.tar.xz mullvadvpn-3fd327525882bc6459ed425de67ed687c949ef3f.zip | |
Add enum for error state cause and update to new values from daemon
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 115 | ||||
| -rw-r--r-- | gui/src/shared/daemon-rpc-types.ts | 84 |
2 files changed, 132 insertions, 67 deletions
diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index a6136bc6f3..9898a1d2c2 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -10,6 +10,7 @@ import { promisify } from 'util'; import { AccountToken, AfterDisconnect, + AuthFailedError, BridgeSettings, BridgeState, ConnectionConfig, @@ -18,15 +19,16 @@ import { DeviceEvent, DeviceState, EndpointObfuscationType, + ErrorState, ErrorStateCause, FirewallPolicyError, + FirewallPolicyErrorType, IAccountData, IAppVersionInfo, IBridgeConstraints, IDevice, IDeviceRemoval, IDnsOptions, - IErrorState, ILocation, IObfuscationEndpoint, IOpenVpnConstraints, @@ -875,71 +877,104 @@ function convertFromTunnelState(tunnelState: grpcTypes.TunnelState): TunnelState } } -function convertFromTunnelStateError(state: grpcTypes.ErrorState.AsObject): IErrorState { - return { - ...state, - cause: convertFromTunnelStateErrorCause(state.cause, state), - blockFailure: state.blockingError - ? convertFromFirewallPolicyError(state.blockingError) - : undefined, +function convertFromTunnelStateError(state: grpcTypes.ErrorState.AsObject): ErrorState { + const baseError = { + blockingError: state.blockingError && convertFromBlockingError(state.blockingError), }; -} -function convertFromTunnelStateErrorCause( - cause: grpcTypes.ErrorState.Cause, - state: grpcTypes.ErrorState.AsObject, -): ErrorStateCause { - switch (cause) { + switch (state.cause) { + case grpcTypes.ErrorState.Cause.AUTH_FAILED: + return { + ...baseError, + cause: ErrorStateCause.authFailed, + authFailedError: convertFromAuthFailedError(state.authFailedError), + }; + case grpcTypes.ErrorState.Cause.TUNNEL_PARAMETER_ERROR: + return { + ...baseError, + cause: ErrorStateCause.tunnelParameterError, + parameterError: convertFromParameterError(state.parameterError), + }; + case grpcTypes.ErrorState.Cause.SET_FIREWALL_POLICY_ERROR: + return { + ...baseError, + cause: ErrorStateCause.setFirewallPolicyError, + policyError: convertFromBlockingError(state.policyError!), + }; + case grpcTypes.ErrorState.Cause.IS_OFFLINE: - return { reason: 'is_offline' }; + return { + ...baseError, + cause: ErrorStateCause.isOffline, + }; case grpcTypes.ErrorState.Cause.SET_DNS_ERROR: - return { reason: 'set_dns_error' }; + return { + ...baseError, + cause: ErrorStateCause.setDnsError, + }; case grpcTypes.ErrorState.Cause.IPV6_UNAVAILABLE: - return { reason: 'ipv6_unavailable' }; - case grpcTypes.ErrorState.Cause.START_TUNNEL_ERROR: - return { reason: 'start_tunnel_error' }; - case grpcTypes.ErrorState.Cause.SET_FIREWALL_POLICY_ERROR: return { - reason: 'set_firewall_policy_error', - details: convertFromFirewallPolicyError(state.policyError!), + ...baseError, + cause: ErrorStateCause.ipv6Unavailable, }; - case grpcTypes.ErrorState.Cause.AUTH_FAILED: - return { reason: 'auth_failed', details: state.authFailReason }; - case grpcTypes.ErrorState.Cause.TUNNEL_PARAMETER_ERROR: { - const parameterErrorMap: Record< - grpcTypes.ErrorState.GenerationError, - TunnelParameterError - > = { - [grpcTypes.ErrorState.GenerationError.NO_MATCHING_RELAY]: 'no_matching_relay', - [grpcTypes.ErrorState.GenerationError.NO_MATCHING_BRIDGE_RELAY]: 'no_matching_bridge_relay', - [grpcTypes.ErrorState.GenerationError.NO_WIREGUARD_KEY]: 'no_wireguard_key', - [grpcTypes.ErrorState.GenerationError.CUSTOM_TUNNEL_HOST_RESOLUTION_ERROR]: - 'custom_tunnel_host_resultion_error', + case grpcTypes.ErrorState.Cause.START_TUNNEL_ERROR: + return { + ...baseError, + cause: ErrorStateCause.startTunnelError, }; - return { reason: 'tunnel_parameter_error', details: parameterErrorMap[state.parameterError] }; - } case grpcTypes.ErrorState.Cause.SPLIT_TUNNEL_ERROR: - return { reason: 'split_tunnel_error' }; + return { + ...baseError, + cause: ErrorStateCause.splitTunnelError, + }; case grpcTypes.ErrorState.Cause.VPN_PERMISSION_DENIED: // VPN_PERMISSION_DENIED is only ever created on Android throw invalidErrorStateCause; } } -function convertFromFirewallPolicyError( +function convertFromBlockingError( error: grpcTypes.ErrorState.FirewallPolicyError.AsObject, ): FirewallPolicyError { switch (error.type) { case grpcTypes.ErrorState.FirewallPolicyError.ErrorType.GENERIC: - return { reason: 'generic' }; + return { type: FirewallPolicyErrorType.generic }; case grpcTypes.ErrorState.FirewallPolicyError.ErrorType.LOCKED: { const pid = error.lockPid; const name = error.lockName; - return { reason: 'locked', details: pid && name ? { pid, name } : undefined }; + return { type: FirewallPolicyErrorType.locked, pid, name }; } } } +function convertFromAuthFailedError(error: grpcTypes.ErrorState.AuthFailedError): AuthFailedError { + switch (error) { + case grpcTypes.ErrorState.AuthFailedError.UNKNOWN: + return AuthFailedError.unknown; + case grpcTypes.ErrorState.AuthFailedError.INVALID_ACCOUNT: + return AuthFailedError.invalidAccount; + case grpcTypes.ErrorState.AuthFailedError.EXPIRED_ACCOUNT: + return AuthFailedError.expiredAccount; + case grpcTypes.ErrorState.AuthFailedError.TOO_MANY_CONNECTIONS: + return AuthFailedError.tooManyConnections; + } +} + +function convertFromParameterError( + error: grpcTypes.ErrorState.GenerationError, +): TunnelParameterError { + switch (error) { + case grpcTypes.ErrorState.GenerationError.NO_MATCHING_RELAY: + return TunnelParameterError.noMatchingRelay; + case grpcTypes.ErrorState.GenerationError.NO_MATCHING_BRIDGE_RELAY: + return TunnelParameterError.noMatchingBridgeRelay; + case grpcTypes.ErrorState.GenerationError.NO_WIREGUARD_KEY: + return TunnelParameterError.noWireguardKey; + case grpcTypes.ErrorState.GenerationError.CUSTOM_TUNNEL_HOST_RESOLUTION_ERROR: + return TunnelParameterError.customTunnelHostResolutionError; + } +} + function convertFromTunnelStateRelayInfo( state: grpcTypes.TunnelStateRelayInfo.AsObject, ): ITunnelStateRelayInfo | undefined { diff --git a/gui/src/shared/daemon-rpc-types.ts b/gui/src/shared/daemon-rpc-types.ts index 735bb91224..4a5f27d98e 100644 --- a/gui/src/shared/daemon-rpc-types.ts +++ b/gui/src/shared/daemon-rpc-types.ts @@ -17,34 +17,69 @@ export interface ILocation { provider?: string; } +export enum FirewallPolicyErrorType { + generic, + locked, +} + export type FirewallPolicyError = - | { reason: 'generic' } + | { type: FirewallPolicyErrorType.generic } | { - reason: 'locked'; - details?: { - name: string; - pid: number; - }; + type: FirewallPolicyErrorType.locked; + name: string; + pid: number; }; -export type TunnelParameterError = - | 'no_matching_relay' - | 'no_matching_bridge_relay' - | 'no_wireguard_key' - | 'custom_tunnel_host_resultion_error'; +export enum ErrorStateCause { + authFailed, + ipv6Unavailable, + setFirewallPolicyError, + setDnsError, + startTunnelError, + tunnelParameterError, + isOffline, + splitTunnelError, +} + +export enum AuthFailedError { + unknown, + invalidAccount, + expiredAccount, + tooManyConnections, +} + +export enum TunnelParameterError { + noMatchingRelay, + noMatchingBridgeRelay, + noWireguardKey, + customTunnelHostResolutionError, +} -export type ErrorStateCause = +export type ErrorState = | { - reason: - | 'ipv6_unavailable' - | 'set_dns_error' - | 'start_tunnel_error' - | 'is_offline' - | 'split_tunnel_error'; + cause: + | ErrorStateCause.ipv6Unavailable + | ErrorStateCause.setDnsError + | ErrorStateCause.startTunnelError + | ErrorStateCause.isOffline + | ErrorStateCause.splitTunnelError; + blockingError?: FirewallPolicyError; } - | { reason: 'set_firewall_policy_error'; details: FirewallPolicyError } - | { reason: 'tunnel_parameter_error'; details: TunnelParameterError } - | { reason: 'auth_failed'; details?: string }; + | { + cause: ErrorStateCause.authFailed; + blockingError?: FirewallPolicyError; + authFailedError: AuthFailedError; + } + | { + cause: ErrorStateCause.tunnelParameterError; + blockingError?: FirewallPolicyError; + parameterError: TunnelParameterError; + } + | { + cause: ErrorStateCause.setFirewallPolicyError; + blockingError?: FirewallPolicyError; + policyError: FirewallPolicyError; + }; export type AfterDisconnect = 'nothing' | 'block' | 'reconnect'; @@ -134,12 +169,7 @@ export type TunnelState = | { state: 'connecting'; details?: ITunnelStateRelayInfo } | { state: 'connected'; details: ITunnelStateRelayInfo } | { state: 'disconnecting'; details: AfterDisconnect } - | { state: 'error'; details: IErrorState }; - -export interface IErrorState { - blockFailure?: FirewallPolicyError; - cause: ErrorStateCause; -} + | { state: 'error'; details: ErrorState }; export type RelayLocation = | { hostname: [string, string, string] } |
