diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-06-15 18:30:30 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-08-01 16:27:17 -0300 |
| commit | 282549ba993803502d25a68ac7a878ddb76cde4e (patch) | |
| tree | bde8f8837950c7a2063a23b935da60dc68881b69 | |
| parent | 0abcde1cac8db5bd86080ee92a39521d3c2bd13c (diff) | |
| download | mullvadvpn-282549ba993803502d25a68ac7a878ddb76cde4e.tar.xz mullvadvpn-282549ba993803502d25a68ac7a878ddb76cde4e.zip | |
Move `InvalidAccountError` triage to `ipc-facade`
| -rw-r--r-- | app/app.js | 35 | ||||
| -rw-r--r-- | app/lib/daemon-rpc.js | 25 |
2 files changed, 25 insertions, 35 deletions
diff --git a/app/app.js b/app/app.js index c10df05deb..8839e3d33e 100644 --- a/app/app.js +++ b/app/app.js @@ -12,18 +12,8 @@ import { log } from './lib/platform'; import ReconnectionBackoff from './lib/reconnection-backoff'; import { DaemonRpc } from './lib/daemon-rpc'; import { setShutdownHandler } from './shutdown-handler'; -import { - RemoteError as JsonRpcTransportRemoteError, - TimeOutError as JsonRpcTransportTimeOutError, -} from './lib/jsonrpc-transport'; -import { - UnknownError, - NoAccountError, - CommunicationError, - InvalidAccountError, - NoDaemonError, -} from './errors'; +import { NoAccountError } from './errors'; import configureStore from './redux/store'; import accountActions from './redux/account/actions'; @@ -144,7 +134,7 @@ export default class AppRenderer { } catch (error) { log.error('Failed to log in,', error.message); - actions.account.loginFailed(this._rpcErrorToBackendError(error)); + actions.account.loginFailed(error); } } @@ -536,27 +526,6 @@ export default class AppRenderer { this._updateTrayIcon(connectionState); } - _rpcErrorToBackendError(e) { - if (e instanceof JsonRpcTransportRemoteError) { - switch (e.code) { - case -200: // Account doesn't exist - return new InvalidAccountError(); - case -32603: // Internal error - // We treat all internal backend errors as the user cannot reach - // api.mullvad.net. This is not always true of course, but it is - // true so often that we choose to disregard the other edge cases - // for now. - return new CommunicationError(); - } - } else if (e instanceof JsonRpcTransportTimeOutError) { - return new CommunicationError(); - } else if (e instanceof NoDaemonError) { - return e; - } - - return new UnknownError(e.message); - } - async _authenticate(sharedSecret: string) { try { await this._daemonRpc.authenticate(sharedSecret); diff --git a/app/lib/daemon-rpc.js b/app/lib/daemon-rpc.js index 72421ed88c..402fbcd76c 100644 --- a/app/lib/daemon-rpc.js +++ b/app/lib/daemon-rpc.js @@ -1,6 +1,11 @@ // @flow -import JsonRpcTransport from './jsonrpc-transport'; +import JsonRpcTransport, { + RemoteError as JsonRpcRemoteError, + TimeOutError as JsonRpcTimeOutError, +} from './jsonrpc-transport'; +import { UnknownError, CommunicationError, InvalidAccountError, NoDaemonError } from '../errors'; + import { object, maybe, @@ -265,7 +270,23 @@ export class DaemonRpc implements DaemonRpcProtocol { async getAccountData(accountToken: AccountToken): Promise<AccountData> { // send the IPC with 30s timeout since the backend will wait // for a HTTP request before replying - const response = await this._transport.send('get_account_data', accountToken, 30000); + let response; + try { + response = await this._transport.send('get_account_data', accountToken, 30000); + } catch (error) { + if (error instanceof JsonRpcRemoteError) { + switch (error.code) { + case -200: // Account doesn't exist + throw new InvalidAccountError(); + case -32603: // Internal error + throw new CommunicationError(); + } + } else if (error instanceof JsonRpcTimeOutError) { + throw new NoDaemonError(); + } + throw new UnknownError(error.message); + } + try { return validate(AccountDataSchema, response); } catch (error) { |
