diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-09-01 08:40:03 +0200 |
|---|---|---|
| committer | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-09-30 09:51:49 +0200 |
| commit | 16289d924b810c202e73bb468a361ad9a4111b72 (patch) | |
| tree | 935f9c42e9b5cb9b76dbc626f2d01ad97f8f03fb | |
| parent | 0113a2421163bd4bc8dda4fa8c15dabc0056f674 (diff) | |
| download | mullvadvpn-16289d924b810c202e73bb468a361ad9a4111b72.tar.xz mullvadvpn-16289d924b810c202e73bb468a361ad9a4111b72.zip | |
Handle daemon error when adding an api access method
| -rw-r--r-- | desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts | 24 | ||||
| -rw-r--r-- | desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts | 2 |
2 files changed, 20 insertions, 6 deletions
diff --git a/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts b/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts index 5c8e6de6e1..90496f4e29 100644 --- a/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts +++ b/desktop/packages/mullvad-vpn/src/main/daemon-rpc.ts @@ -4,6 +4,7 @@ import { BoolValue, StringValue } from 'google-protobuf/google/protobuf/wrappers import { types as grpcTypes } from 'management-interface'; import { + AccessMethodExistsError, AccessMethodSetting, AccountDataError, AccountDataResponse, @@ -601,12 +602,23 @@ export class DaemonRpc extends GrpcClient { } } - public async addApiAccessMethod(method: NewAccessMethodSetting): Promise<string> { - const result = await this.call<grpcTypes.NewAccessMethodSetting, grpcTypes.UUID>( - this.client.addApiAccessMethod, - convertToNewApiAccessMethodSetting(method), - ); - return result.getValue(); + public async addApiAccessMethod( + method: NewAccessMethodSetting, + ): Promise<string | AccessMethodExistsError> { + try { + const result = await this.call<grpcTypes.NewAccessMethodSetting, grpcTypes.UUID>( + this.client.addApiAccessMethod, + convertToNewApiAccessMethodSetting(method), + ); + return result.getValue(); + } catch (e) { + const error = e as grpc.ServiceError; + if (error.code === 6) { + return { type: 'name already exists' }; + } else { + throw error; + } + } } public async updateApiAccessMethod(method: AccessMethodSetting) { diff --git a/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts b/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts index 117f002289..026df6d189 100644 --- a/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts +++ b/desktop/packages/mullvad-vpn/src/shared/daemon-rpc-types.ts @@ -487,6 +487,8 @@ export type NewCustomList = Pick<ICustomList, 'name' | 'locations'>; export type CustomListError = { type: 'name already exists' }; +export type AccessMethodExistsError = { type: 'name already exists' }; + export interface ISettings { allowLan: boolean; autoConnect: boolean; |
