@@ -78,8 +78,8 @@ import net.mullvad.mullvadvpn.lib.model.GetDeviceListError
78
78
import net.mullvad.mullvadvpn.lib.model.GetDeviceStateError
79
79
import net.mullvad.mullvadvpn.lib.model.GetVersionInfoError
80
80
import net.mullvad.mullvadvpn.lib.model.LoginAccountError
81
- import net.mullvad.mullvadvpn.lib.model.NameAlreadyExists
82
81
import net.mullvad.mullvadvpn.lib.model.LogoutAccountError
82
+ import net.mullvad.mullvadvpn.lib.model.NameAlreadyExists
83
83
import net.mullvad.mullvadvpn.lib.model.NewAccessMethodSetting
84
84
import net.mullvad.mullvadvpn.lib.model.ObfuscationSettings
85
85
import net.mullvad.mullvadvpn.lib.model.Ownership as ModelOwnership
@@ -246,16 +246,19 @@ class ManagementService(
246
246
suspend fun getDevice (): Either <GetDeviceStateError , ModelDeviceState > =
247
247
Either .catch { grpc.getDevice(Empty .getDefaultInstance()) }
248
248
.map { it.toDomain() }
249
+ .onLeft { Logger .e(" Get device error" , it) }
249
250
.mapLeft { GetDeviceStateError .Unknown (it) }
250
251
251
252
suspend fun updateDevice (): Either <DeviceUpdateError , Unit > =
252
253
Either .catch { grpc.updateDevice(Empty .getDefaultInstance()) }
253
254
.mapEmpty()
255
+ .onLeft { Logger .e(" Update device error" , it) }
254
256
.mapLeft { DeviceUpdateError (it) }
255
257
256
258
suspend fun getDeviceList (token : AccountNumber ): Either <GetDeviceListError , List <Device >> =
257
259
Either .catch { grpc.listDevices(StringValue .of(token.value)) }
258
260
.map { it.devicesList.map(ManagementInterface .Device ::toDomain) }
261
+ .onLeft { Logger .e(" Get device list error" , it) }
259
262
.mapLeft { GetDeviceListError .Unknown (it) }
260
263
261
264
suspend fun removeDevice (
@@ -271,18 +274,22 @@ class ManagementService(
271
274
)
272
275
}
273
276
.mapEmpty()
277
+ .onLeft { Logger .e(" Remove device error" , it) }
274
278
.mapLeft { DeleteDeviceError .Unknown (it) }
275
279
276
280
suspend fun connect (): Either <ConnectError , Boolean > =
277
281
Either .catch { grpc.connectTunnel(Empty .getDefaultInstance()).value }
282
+ .onLeft { Logger .e(" Connect error" , it) }
278
283
.mapLeft(ConnectError ::Unknown )
279
284
280
285
suspend fun disconnect (): Either <ConnectError , Boolean > =
281
286
Either .catch { grpc.disconnectTunnel(Empty .getDefaultInstance()).value }
287
+ .onLeft { Logger .e(" Disconnect error" , it) }
282
288
.mapLeft(ConnectError ::Unknown )
283
289
284
290
suspend fun reconnect (): Either <ConnectError , Boolean > =
285
291
Either .catch { grpc.reconnectTunnel(Empty .getDefaultInstance()).value }
292
+ .onLeft { Logger .e(" Reconnect error" , it) }
286
293
.mapLeft(ConnectError ::Unknown )
287
294
288
295
private suspend fun getTunnelState (): ModelTunnelState =
@@ -301,13 +308,15 @@ class ManagementService(
301
308
// will get 404 until the api have been published, thus we need to ignore error downstream.
302
309
private suspend fun getVersionInfo (): Either <GetVersionInfoError , ModelAppVersionInfo > =
303
310
Either .catch { grpc.getVersionInfo(Empty .getDefaultInstance()).toDomain() }
311
+ .onLeft { Logger .e(" Get version info error" , it) }
304
312
.mapLeft { GetVersionInfoError .Unknown (it) }
305
313
306
314
private suspend fun getCurrentApiAccessMethod (): ApiAccessMethodSetting =
307
315
grpc.getCurrentApiAccessMethod(Empty .getDefaultInstance()).toDomain()
308
316
309
317
suspend fun logoutAccount (): Either <LogoutAccountError , Unit > =
310
318
Either .catch { grpc.logoutAccount(Empty .getDefaultInstance()) }
319
+ .onLeft { Logger .e(" Logout account error" , it) }
311
320
.mapLeft(LogoutAccountError ::Unknown )
312
321
.mapEmpty()
313
322
@@ -326,6 +335,7 @@ class ManagementService(
326
335
327
336
suspend fun clearAccountHistory (): Either <ClearAccountHistoryError , Unit > =
328
337
Either .catch { grpc.clearAccountHistory(Empty .getDefaultInstance()) }
338
+ .onLeft { Logger .e(" Clear account history error" , it) }
329
339
.mapLeft(ClearAccountHistoryError ::Unknown )
330
340
.mapEmpty()
331
341
@@ -338,6 +348,7 @@ class ManagementService(
338
348
null
339
349
}
340
350
}
351
+ .onLeft { Logger .e(" Get account history error" , it) }
341
352
.mapLeft(GetAccountHistoryError ::Unknown )
342
353
343
354
private suspend fun getInitialServiceState () {
@@ -357,17 +368,20 @@ class ManagementService(
357
368
accountNumber : AccountNumber
358
369
): Either <GetAccountDataError , AccountData > =
359
370
Either .catch { grpc.getAccountData(StringValue .of(accountNumber.value)).toDomain() }
371
+ .onLeft { Logger .e(" Get account data error" , it) }
360
372
.mapLeft(GetAccountDataError ::Unknown )
361
373
362
374
suspend fun createAccount (): Either <CreateAccountError , AccountNumber > =
363
375
Either .catch {
364
376
val accountNumberStringValue = grpc.createNewAccount(Empty .getDefaultInstance())
365
377
AccountNumber (accountNumberStringValue.value)
366
378
}
379
+ .onLeft { Logger .e(" Create account error" , it) }
367
380
.mapLeft(CreateAccountError ::Unknown )
368
381
369
382
suspend fun setDnsOptions (dnsOptions : ModelDnsOptions ): Either <SetDnsOptionsError , Unit > =
370
383
Either .catch { grpc.setDnsOptions(dnsOptions.fromDomain()) }
384
+ .onLeft { Logger .e(" Set dns options error" , it) }
371
385
.mapLeft(SetDnsOptionsError ::Unknown )
372
386
.mapEmpty()
373
387
@@ -377,6 +391,7 @@ class ManagementService(
377
391
val updated = DnsOptions .state.set(currentDnsOptions, dnsState)
378
392
grpc.setDnsOptions(updated.fromDomain())
379
393
}
394
+ .onLeft { Logger .e(" Set dns state error" , it) }
380
395
.mapLeft(SetDnsOptionsError ::Unknown )
381
396
.mapEmpty()
382
397
@@ -390,6 +405,7 @@ class ManagementService(
390
405
391
406
grpc.setDnsOptions(updatedDnsOptions.fromDomain())
392
407
}
408
+ .onLeft { Logger .e(" Set custom dns error" , it) }
393
409
.mapLeft(SetDnsOptionsError ::Unknown )
394
410
.mapEmpty()
395
411
@@ -401,6 +417,7 @@ class ManagementService(
401
417
grpc.setDnsOptions(updatedDnsOptions.fromDomain())
402
418
updatedDnsOptions.customOptions.addresses.lastIndex
403
419
}
420
+ .onLeft { Logger .e(" Add custom dns error" , it) }
404
421
.mapLeft(SetDnsOptionsError ::Unknown )
405
422
406
423
suspend fun deleteCustomDns (index : Int ): Either <SetDnsOptionsError , Unit > =
@@ -414,23 +431,27 @@ class ManagementService(
414
431
}
415
432
grpc.setDnsOptions(updatedDnsOptions.fromDomain())
416
433
}
434
+ .onLeft { Logger .e(" Delete custom dns error" , it) }
417
435
.mapLeft(SetDnsOptionsError ::Unknown )
418
436
.mapEmpty()
419
437
420
438
suspend fun setWireguardMtu (value : Int ): Either <SetWireguardMtuError , Unit > =
421
439
Either .catch { grpc.setWireguardMtu(UInt32Value .of(value)) }
440
+ .onLeft { Logger .e(" Set wireguard mtu error" , it) }
422
441
.mapLeft(SetWireguardMtuError ::Unknown )
423
442
.mapEmpty()
424
443
425
444
suspend fun resetWireguardMtu (): Either <SetWireguardMtuError , Unit > =
426
445
Either .catch { grpc.setWireguardMtu(UInt32Value .newBuilder().clearValue().build()) }
446
+ .onLeft { Logger .e(" Reset wireguard mtu error" , it) }
427
447
.mapLeft(SetWireguardMtuError ::Unknown )
428
448
.mapEmpty()
429
449
430
450
suspend fun setWireguardQuantumResistant (
431
451
value : ModelQuantumResistantState
432
452
): Either <SetWireguardQuantumResistantError , Unit > =
433
453
Either .catch { grpc.setQuantumResistantTunnel(value.toDomain()) }
454
+ .onLeft { Logger .e(" Set wireguard quantum resistant error" , it) }
434
455
.mapLeft(SetWireguardQuantumResistantError ::Unknown )
435
456
.mapEmpty()
436
457
@@ -446,6 +467,7 @@ class ManagementService(
446
467
}
447
468
grpc.setObfuscationSettings(updatedObfuscationSettings.fromDomain())
448
469
}
470
+ .onLeft { Logger .e(" Set obfuscation error" , it) }
449
471
.mapLeft(SetObfuscationOptionsError ::Unknown )
450
472
.mapEmpty()
451
473
@@ -459,16 +481,19 @@ class ManagementService(
459
481
}
460
482
grpc.setObfuscationSettings(updatedSettings.fromDomain())
461
483
}
484
+ .onLeft { Logger .e(" Set obfuscation port error" , it) }
462
485
.mapLeft(SetObfuscationOptionsError ::Unknown )
463
486
.mapEmpty()
464
487
465
488
suspend fun setAutoConnect (isEnabled : Boolean ): Either <SetAutoConnectError , Unit > =
466
489
Either .catch { grpc.setAutoConnect(BoolValue .of(isEnabled)) }
490
+ .onLeft { Logger .e(" Set auto connect error" , it) }
467
491
.mapLeft(SetAutoConnectError ::Unknown )
468
492
.mapEmpty()
469
493
470
494
suspend fun setAllowLan (allow : Boolean ): Either <SetAllowLanError , Unit > =
471
495
Either .catch { grpc.setAllowLan(BoolValue .of(allow)) }
496
+ .onLeft { Logger .e(" Set allow lan error" , it) }
472
497
.mapLeft(SetAllowLanError ::Unknown )
473
498
.mapEmpty()
474
499
@@ -482,6 +507,7 @@ class ManagementService(
482
507
)
483
508
grpc.setRelaySettings(updatedRelaySettings.fromDomain())
484
509
}
510
+ .onLeft { Logger .e(" Set relay location error" , it) }
485
511
.mapLeft(SetRelayLocationError ::Unknown )
486
512
.mapEmpty()
487
513
@@ -509,11 +535,13 @@ class ManagementService(
509
535
510
536
suspend fun deleteCustomList (id : CustomListId ): Either <DeleteCustomListError , Unit > =
511
537
Either .catch { grpc.deleteCustomList(StringValue .of(id.value)) }
538
+ .onLeft { Logger .e(" Delete custom list error" , it) }
512
539
.mapLeft(::UnknownCustomListError )
513
540
.mapEmpty()
514
541
515
542
suspend fun clearAllRelayOverrides (): Either <ClearAllOverridesError , Unit > =
516
543
Either .catch { grpc.clearAllRelayOverrides(Empty .getDefaultInstance()) }
544
+ .onLeft { Logger .e(" Clear all relay overrides error" , it) }
517
545
.mapLeft(ClearAllOverridesError ::Unknown )
518
546
.mapEmpty()
519
547
@@ -537,6 +565,7 @@ class ManagementService(
537
565
RelaySettings .relayConstraints.wireguardConstraints.set(relaySettings, value)
538
566
grpc.setRelaySettings(updated.fromDomain())
539
567
}
568
+ .onLeft { Logger .e(" Set wireguard constraints error" , it) }
540
569
.mapLeft(SetWireguardConstraintsError ::Unknown )
541
570
.mapEmpty()
542
571
@@ -555,6 +584,7 @@ class ManagementService(
555
584
}
556
585
grpc.setRelaySettings(updated.fromDomain())
557
586
}
587
+ .onLeft { Logger .e(" Set ownership and providers error" , it) }
558
588
.mapLeft(SetWireguardConstraintsError ::Unknown )
559
589
.mapEmpty()
560
590
@@ -566,6 +596,7 @@ class ManagementService(
566
596
val updated = RelaySettings .relayConstraints.ownership.set(relaySettings, ownership)
567
597
grpc.setRelaySettings(updated.fromDomain())
568
598
}
599
+ .onLeft { Logger .e(" Set ownership error" , it) }
569
600
.mapLeft(SetWireguardConstraintsError ::Unknown )
570
601
.mapEmpty()
571
602
@@ -578,6 +609,7 @@ class ManagementService(
578
609
RelaySettings .relayConstraints.providers.set(relaySettings, providersConstraint)
579
610
grpc.setRelaySettings(updated.fromDomain())
580
611
}
612
+ .onLeft { Logger .e(" Set providers error" , it) }
581
613
.mapLeft(SetWireguardConstraintsError ::Unknown )
582
614
.mapEmpty()
583
615
@@ -596,59 +628,69 @@ class ManagementService(
596
628
597
629
suspend fun initializePlayPurchase (): Either <PlayPurchaseInitError , PlayPurchasePaymentToken > =
598
630
Either .catch { grpc.initPlayPurchase(Empty .getDefaultInstance()).toDomain() }
631
+ .onLeft { Logger .e(" Initialize play purchase error" , it) }
599
632
.mapLeft { PlayPurchaseInitError .OtherError }
600
633
601
634
suspend fun verifyPlayPurchase (purchase : PlayPurchase ): Either <PlayPurchaseVerifyError , Unit > =
602
635
Either .catch { grpc.verifyPlayPurchase(purchase.fromDomain()) }
636
+ .onLeft { Logger .e(" Verify play purchase error" , it) }
603
637
.mapLeft { PlayPurchaseVerifyError .OtherError }
604
638
.mapEmpty()
605
639
606
640
suspend fun addSplitTunnelingApp (app : AppId ): Either <AddSplitTunnelingAppError , Unit > =
607
641
Either .catch { grpc.addSplitTunnelApp(StringValue .of(app.value)) }
642
+ .onLeft { Logger .e(" Add split tunneling app error" , it) }
608
643
.mapLeft(AddSplitTunnelingAppError ::Unknown )
609
644
.mapEmpty()
610
645
611
646
suspend fun removeSplitTunnelingApp (app : AppId ): Either <RemoveSplitTunnelingAppError , Unit > =
612
647
Either .catch { grpc.removeSplitTunnelApp(StringValue .of(app.value)) }
648
+ .onLeft { Logger .e(" Remove split tunneling app error" , it) }
613
649
.mapLeft(RemoveSplitTunnelingAppError ::Unknown )
614
650
.mapEmpty()
615
651
616
652
suspend fun setSplitTunnelingState (
617
653
enabled : Boolean
618
654
): Either <RemoveSplitTunnelingAppError , Unit > =
619
655
Either .catch { grpc.setSplitTunnelState(BoolValue .of(enabled)) }
656
+ .onLeft { Logger .e(" Set split tunneling state error" , it) }
620
657
.mapLeft(RemoveSplitTunnelingAppError ::Unknown )
621
658
.mapEmpty()
622
659
623
660
suspend fun getWebsiteAuthToken (): Either <Throwable , WebsiteAuthToken > =
624
661
Either .catch { grpc.getWwwAuthToken(Empty .getDefaultInstance()) }
662
+ .onLeft { Logger .e(" Get website auth token error" , it) }
625
663
.map { WebsiteAuthToken .fromString(it.value) }
626
664
627
665
suspend fun addApiAccessMethod (
628
666
newAccessMethodSetting : NewAccessMethodSetting
629
667
): Either <AddApiAccessMethodError , ApiAccessMethodId > =
630
668
Either .catch { grpc.addApiAccessMethod(newAccessMethodSetting.fromDomain()) }
669
+ .onLeft { Logger .e(" Add api access method error" , it) }
631
670
.mapLeft(AddApiAccessMethodError ::Unknown )
632
671
.map { ApiAccessMethodId .fromString(it.value) }
633
672
634
673
suspend fun removeApiAccessMethod (
635
674
apiAccessMethodId : ApiAccessMethodId
636
675
): Either <RemoveApiAccessMethodError , Unit > =
637
676
Either .catch { grpc.removeApiAccessMethod(apiAccessMethodId.fromDomain()) }
677
+ .onLeft { Logger .e(" Remove api access method error" , it) }
638
678
.mapLeft(RemoveApiAccessMethodError ::Unknown )
639
679
.mapEmpty()
640
680
641
681
suspend fun setApiAccessMethod (
642
682
apiAccessMethodId : ApiAccessMethodId
643
683
): Either <SetApiAccessMethodError , Unit > =
644
684
Either .catch { grpc.setApiAccessMethod(apiAccessMethodId.fromDomain()) }
685
+ .onLeft { Logger .e(" Set api access method error" , it) }
645
686
.mapLeft(SetApiAccessMethodError ::Unknown )
646
687
.mapEmpty()
647
688
648
689
suspend fun updateApiAccessMethod (
649
690
apiAccessMethodSetting : ApiAccessMethodSetting
650
691
): Either <UpdateApiAccessMethodError , Unit > =
651
692
Either .catch { grpc.updateApiAccessMethod(apiAccessMethodSetting.fromDomain()) }
693
+ .onLeft { Logger .e(" Update api access method error" , it) }
652
694
.mapLeft(::UnknownApiAccessMethodError )
653
695
.mapEmpty()
654
696
0 commit comments