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 /app/lib | |
| parent | 0abcde1cac8db5bd86080ee92a39521d3c2bd13c (diff) | |
| download | mullvadvpn-282549ba993803502d25a68ac7a878ddb76cde4e.tar.xz mullvadvpn-282549ba993803502d25a68ac7a878ddb76cde4e.zip | |
Move `InvalidAccountError` triage to `ipc-facade`
Diffstat (limited to 'app/lib')
| -rw-r--r-- | app/lib/daemon-rpc.js | 25 |
1 files changed, 23 insertions, 2 deletions
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) { |
