Skip to content

Commit

Permalink
Add error logs for all unknown errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Aug 7, 2024
1 parent 4fec19f commit 7aff65e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,19 @@ class ConnectViewModel(
}

fun onDisconnectClick() {
viewModelScope.launch { connectionProxy.disconnect().onLeft {
_uiSideEffect.send(UiSideEffect.ConnectError.Generic)
} }
viewModelScope.launch {
connectionProxy.disconnect().onLeft {
_uiSideEffect.send(UiSideEffect.ConnectError.Generic)
}
}
}

fun onReconnectClick() {
viewModelScope.launch { connectionProxy.reconnect().onLeft {
_uiSideEffect.send(UiSideEffect.ConnectError.Generic)
} }
viewModelScope.launch {
connectionProxy.reconnect().onLeft {
_uiSideEffect.send(UiSideEffect.ConnectError.Generic)
}
}
}

fun onConnectClick() {
Expand Down Expand Up @@ -160,9 +164,11 @@ class ConnectViewModel(
}

fun onCancelClick() {
viewModelScope.launch { connectionProxy.disconnect().onLeft {
_uiSideEffect.send(UiSideEffect.ConnectError.Generic)
} }
viewModelScope.launch {
connectionProxy.disconnect().onLeft {
_uiSideEffect.send(UiSideEffect.ConnectError.Generic)
}
}
}

fun onManageAccountClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ class OutOfTimeViewModel(
}

fun onDisconnectClick() {
viewModelScope.launch { connectionProxy.disconnect().onLeft {
_uiSideEffect.send(UiSideEffect.GenericError)
} }
viewModelScope.launch {
connectionProxy.disconnect().onLeft { _uiSideEffect.send(UiSideEffect.GenericError) }
}
}

private fun verifyPurchases() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ class WelcomeViewModel(
}

fun onDisconnectClick() {
viewModelScope.launch { connectionProxy.disconnect().onLeft {
_uiSideEffect.send(UiSideEffect.GenericError)
} }
viewModelScope.launch {
connectionProxy.disconnect().onLeft { _uiSideEffect.send(UiSideEffect.GenericError) }
}
}

private fun verifyPurchases() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ import net.mullvad.mullvadvpn.lib.model.GetDeviceListError
import net.mullvad.mullvadvpn.lib.model.GetDeviceStateError
import net.mullvad.mullvadvpn.lib.model.GetVersionInfoError
import net.mullvad.mullvadvpn.lib.model.LoginAccountError
import net.mullvad.mullvadvpn.lib.model.NameAlreadyExists
import net.mullvad.mullvadvpn.lib.model.LogoutAccountError
import net.mullvad.mullvadvpn.lib.model.NameAlreadyExists
import net.mullvad.mullvadvpn.lib.model.NewAccessMethodSetting
import net.mullvad.mullvadvpn.lib.model.ObfuscationSettings
import net.mullvad.mullvadvpn.lib.model.Ownership as ModelOwnership
Expand Down Expand Up @@ -246,16 +246,19 @@ class ManagementService(
suspend fun getDevice(): Either<GetDeviceStateError, ModelDeviceState> =
Either.catch { grpc.getDevice(Empty.getDefaultInstance()) }
.map { it.toDomain() }
.onLeft { Logger.e("Get device error", it) }
.mapLeft { GetDeviceStateError.Unknown(it) }

suspend fun updateDevice(): Either<DeviceUpdateError, Unit> =
Either.catch { grpc.updateDevice(Empty.getDefaultInstance()) }
.mapEmpty()
.onLeft { Logger.e("Update device error", it) }
.mapLeft { DeviceUpdateError(it) }

suspend fun getDeviceList(token: AccountNumber): Either<GetDeviceListError, List<Device>> =
Either.catch { grpc.listDevices(StringValue.of(token.value)) }
.map { it.devicesList.map(ManagementInterface.Device::toDomain) }
.onLeft { Logger.e("Get device list error", it) }
.mapLeft { GetDeviceListError.Unknown(it) }

suspend fun removeDevice(
Expand All @@ -271,18 +274,22 @@ class ManagementService(
)
}
.mapEmpty()
.onLeft { Logger.e("Remove device error", it) }
.mapLeft { DeleteDeviceError.Unknown(it) }

suspend fun connect(): Either<ConnectError, Boolean> =
Either.catch { grpc.connectTunnel(Empty.getDefaultInstance()).value }
.onLeft { Logger.e("Connect error", it) }
.mapLeft(ConnectError::Unknown)

suspend fun disconnect(): Either<ConnectError, Boolean> =
Either.catch { grpc.disconnectTunnel(Empty.getDefaultInstance()).value }
.onLeft { Logger.e("Disconnect error", it) }
.mapLeft(ConnectError::Unknown)

suspend fun reconnect(): Either<ConnectError, Boolean> =
Either.catch { grpc.reconnectTunnel(Empty.getDefaultInstance()).value }
.onLeft { Logger.e("Reconnect error", it) }
.mapLeft(ConnectError::Unknown)

private suspend fun getTunnelState(): ModelTunnelState =
Expand All @@ -301,13 +308,15 @@ class ManagementService(
// will get 404 until the api have been published, thus we need to ignore error downstream.
private suspend fun getVersionInfo(): Either<GetVersionInfoError, ModelAppVersionInfo> =
Either.catch { grpc.getVersionInfo(Empty.getDefaultInstance()).toDomain() }
.onLeft { Logger.e("Get version info error", it) }
.mapLeft { GetVersionInfoError.Unknown(it) }

private suspend fun getCurrentApiAccessMethod(): ApiAccessMethodSetting =
grpc.getCurrentApiAccessMethod(Empty.getDefaultInstance()).toDomain()

suspend fun logoutAccount(): Either<LogoutAccountError, Unit> =
Either.catch { grpc.logoutAccount(Empty.getDefaultInstance()) }
.onLeft { Logger.e("Logout account error", it) }
.mapLeft(LogoutAccountError::Unknown)
.mapEmpty()

Expand All @@ -326,6 +335,7 @@ class ManagementService(

suspend fun clearAccountHistory(): Either<ClearAccountHistoryError, Unit> =
Either.catch { grpc.clearAccountHistory(Empty.getDefaultInstance()) }
.onLeft { Logger.e("Clear account history error", it) }
.mapLeft(ClearAccountHistoryError::Unknown)
.mapEmpty()

Expand All @@ -338,6 +348,7 @@ class ManagementService(
null
}
}
.onLeft { Logger.e("Get account history error", it) }
.mapLeft(GetAccountHistoryError::Unknown)

private suspend fun getInitialServiceState() {
Expand All @@ -357,17 +368,20 @@ class ManagementService(
accountNumber: AccountNumber
): Either<GetAccountDataError, AccountData> =
Either.catch { grpc.getAccountData(StringValue.of(accountNumber.value)).toDomain() }
.onLeft { Logger.e("Get account data error", it) }
.mapLeft(GetAccountDataError::Unknown)

suspend fun createAccount(): Either<CreateAccountError, AccountNumber> =
Either.catch {
val accountNumberStringValue = grpc.createNewAccount(Empty.getDefaultInstance())
AccountNumber(accountNumberStringValue.value)
}
.onLeft { Logger.e("Create account error", it) }
.mapLeft(CreateAccountError::Unknown)

suspend fun setDnsOptions(dnsOptions: ModelDnsOptions): Either<SetDnsOptionsError, Unit> =
Either.catch { grpc.setDnsOptions(dnsOptions.fromDomain()) }
.onLeft { Logger.e("Set dns options error", it) }
.mapLeft(SetDnsOptionsError::Unknown)
.mapEmpty()

Expand All @@ -377,6 +391,7 @@ class ManagementService(
val updated = DnsOptions.state.set(currentDnsOptions, dnsState)
grpc.setDnsOptions(updated.fromDomain())
}
.onLeft { Logger.e("Set dns state error", it) }
.mapLeft(SetDnsOptionsError::Unknown)
.mapEmpty()

Expand All @@ -390,6 +405,7 @@ class ManagementService(

grpc.setDnsOptions(updatedDnsOptions.fromDomain())
}
.onLeft { Logger.e("Set custom dns error", it) }
.mapLeft(SetDnsOptionsError::Unknown)
.mapEmpty()

Expand All @@ -401,6 +417,7 @@ class ManagementService(
grpc.setDnsOptions(updatedDnsOptions.fromDomain())
updatedDnsOptions.customOptions.addresses.lastIndex
}
.onLeft { Logger.e("Add custom dns error", it) }
.mapLeft(SetDnsOptionsError::Unknown)

suspend fun deleteCustomDns(index: Int): Either<SetDnsOptionsError, Unit> =
Expand All @@ -414,23 +431,27 @@ class ManagementService(
}
grpc.setDnsOptions(updatedDnsOptions.fromDomain())
}
.onLeft { Logger.e("Delete custom dns error", it) }
.mapLeft(SetDnsOptionsError::Unknown)
.mapEmpty()

suspend fun setWireguardMtu(value: Int): Either<SetWireguardMtuError, Unit> =
Either.catch { grpc.setWireguardMtu(UInt32Value.of(value)) }
.onLeft { Logger.e("Set wireguard mtu error", it) }
.mapLeft(SetWireguardMtuError::Unknown)
.mapEmpty()

suspend fun resetWireguardMtu(): Either<SetWireguardMtuError, Unit> =
Either.catch { grpc.setWireguardMtu(UInt32Value.newBuilder().clearValue().build()) }
.onLeft { Logger.e("Reset wireguard mtu error", it) }
.mapLeft(SetWireguardMtuError::Unknown)
.mapEmpty()

suspend fun setWireguardQuantumResistant(
value: ModelQuantumResistantState
): Either<SetWireguardQuantumResistantError, Unit> =
Either.catch { grpc.setQuantumResistantTunnel(value.toDomain()) }
.onLeft { Logger.e("Set wireguard quantum resistant error", it) }
.mapLeft(SetWireguardQuantumResistantError::Unknown)
.mapEmpty()

Expand All @@ -446,6 +467,7 @@ class ManagementService(
}
grpc.setObfuscationSettings(updatedObfuscationSettings.fromDomain())
}
.onLeft { Logger.e("Set obfuscation error", it) }
.mapLeft(SetObfuscationOptionsError::Unknown)
.mapEmpty()

Expand All @@ -459,16 +481,19 @@ class ManagementService(
}
grpc.setObfuscationSettings(updatedSettings.fromDomain())
}
.onLeft { Logger.e("Set obfuscation port error", it) }
.mapLeft(SetObfuscationOptionsError::Unknown)
.mapEmpty()

suspend fun setAutoConnect(isEnabled: Boolean): Either<SetAutoConnectError, Unit> =
Either.catch { grpc.setAutoConnect(BoolValue.of(isEnabled)) }
.onLeft { Logger.e("Set auto connect error", it) }
.mapLeft(SetAutoConnectError::Unknown)
.mapEmpty()

suspend fun setAllowLan(allow: Boolean): Either<SetAllowLanError, Unit> =
Either.catch { grpc.setAllowLan(BoolValue.of(allow)) }
.onLeft { Logger.e("Set allow lan error", it) }
.mapLeft(SetAllowLanError::Unknown)
.mapEmpty()

Expand All @@ -482,6 +507,7 @@ class ManagementService(
)
grpc.setRelaySettings(updatedRelaySettings.fromDomain())
}
.onLeft { Logger.e("Set relay location error", it) }
.mapLeft(SetRelayLocationError::Unknown)
.mapEmpty()

Expand Down Expand Up @@ -509,11 +535,13 @@ class ManagementService(

suspend fun deleteCustomList(id: CustomListId): Either<DeleteCustomListError, Unit> =
Either.catch { grpc.deleteCustomList(StringValue.of(id.value)) }
.onLeft { Logger.e("Delete custom list error", it) }
.mapLeft(::UnknownCustomListError)
.mapEmpty()

suspend fun clearAllRelayOverrides(): Either<ClearAllOverridesError, Unit> =
Either.catch { grpc.clearAllRelayOverrides(Empty.getDefaultInstance()) }
.onLeft { Logger.e("Clear all relay overrides error", it) }
.mapLeft(ClearAllOverridesError::Unknown)
.mapEmpty()

Expand All @@ -537,6 +565,7 @@ class ManagementService(
RelaySettings.relayConstraints.wireguardConstraints.set(relaySettings, value)
grpc.setRelaySettings(updated.fromDomain())
}
.onLeft { Logger.e("Set wireguard constraints error", it) }
.mapLeft(SetWireguardConstraintsError::Unknown)
.mapEmpty()

Expand All @@ -555,6 +584,7 @@ class ManagementService(
}
grpc.setRelaySettings(updated.fromDomain())
}
.onLeft { Logger.e("Set ownership and providers error", it) }
.mapLeft(SetWireguardConstraintsError::Unknown)
.mapEmpty()

Expand All @@ -566,6 +596,7 @@ class ManagementService(
val updated = RelaySettings.relayConstraints.ownership.set(relaySettings, ownership)
grpc.setRelaySettings(updated.fromDomain())
}
.onLeft { Logger.e("Set ownership error", it) }
.mapLeft(SetWireguardConstraintsError::Unknown)
.mapEmpty()

Expand All @@ -578,6 +609,7 @@ class ManagementService(
RelaySettings.relayConstraints.providers.set(relaySettings, providersConstraint)
grpc.setRelaySettings(updated.fromDomain())
}
.onLeft { Logger.e("Set providers error", it) }
.mapLeft(SetWireguardConstraintsError::Unknown)
.mapEmpty()

Expand All @@ -596,59 +628,69 @@ class ManagementService(

suspend fun initializePlayPurchase(): Either<PlayPurchaseInitError, PlayPurchasePaymentToken> =
Either.catch { grpc.initPlayPurchase(Empty.getDefaultInstance()).toDomain() }
.onLeft { Logger.e("Initialize play purchase error", it) }
.mapLeft { PlayPurchaseInitError.OtherError }

suspend fun verifyPlayPurchase(purchase: PlayPurchase): Either<PlayPurchaseVerifyError, Unit> =
Either.catch { grpc.verifyPlayPurchase(purchase.fromDomain()) }
.onLeft { Logger.e("Verify play purchase error", it) }
.mapLeft { PlayPurchaseVerifyError.OtherError }
.mapEmpty()

suspend fun addSplitTunnelingApp(app: AppId): Either<AddSplitTunnelingAppError, Unit> =
Either.catch { grpc.addSplitTunnelApp(StringValue.of(app.value)) }
.onLeft { Logger.e("Add split tunneling app error", it) }
.mapLeft(AddSplitTunnelingAppError::Unknown)
.mapEmpty()

suspend fun removeSplitTunnelingApp(app: AppId): Either<RemoveSplitTunnelingAppError, Unit> =
Either.catch { grpc.removeSplitTunnelApp(StringValue.of(app.value)) }
.onLeft { Logger.e("Remove split tunneling app error", it) }
.mapLeft(RemoveSplitTunnelingAppError::Unknown)
.mapEmpty()

suspend fun setSplitTunnelingState(
enabled: Boolean
): Either<RemoveSplitTunnelingAppError, Unit> =
Either.catch { grpc.setSplitTunnelState(BoolValue.of(enabled)) }
.onLeft { Logger.e("Set split tunneling state error", it) }
.mapLeft(RemoveSplitTunnelingAppError::Unknown)
.mapEmpty()

suspend fun getWebsiteAuthToken(): Either<Throwable, WebsiteAuthToken> =
Either.catch { grpc.getWwwAuthToken(Empty.getDefaultInstance()) }
.onLeft { Logger.e("Get website auth token error", it) }
.map { WebsiteAuthToken.fromString(it.value) }

suspend fun addApiAccessMethod(
newAccessMethodSetting: NewAccessMethodSetting
): Either<AddApiAccessMethodError, ApiAccessMethodId> =
Either.catch { grpc.addApiAccessMethod(newAccessMethodSetting.fromDomain()) }
.onLeft { Logger.e("Add api access method error", it) }
.mapLeft(AddApiAccessMethodError::Unknown)
.map { ApiAccessMethodId.fromString(it.value) }

suspend fun removeApiAccessMethod(
apiAccessMethodId: ApiAccessMethodId
): Either<RemoveApiAccessMethodError, Unit> =
Either.catch { grpc.removeApiAccessMethod(apiAccessMethodId.fromDomain()) }
.onLeft { Logger.e("Remove api access method error", it) }
.mapLeft(RemoveApiAccessMethodError::Unknown)
.mapEmpty()

suspend fun setApiAccessMethod(
apiAccessMethodId: ApiAccessMethodId
): Either<SetApiAccessMethodError, Unit> =
Either.catch { grpc.setApiAccessMethod(apiAccessMethodId.fromDomain()) }
.onLeft { Logger.e("Set api access method error", it) }
.mapLeft(SetApiAccessMethodError::Unknown)
.mapEmpty()

suspend fun updateApiAccessMethod(
apiAccessMethodSetting: ApiAccessMethodSetting
): Either<UpdateApiAccessMethodError, Unit> =
Either.catch { grpc.updateApiAccessMethod(apiAccessMethodSetting.fromDomain()) }
.onLeft { Logger.e("Update api access method error", it) }
.mapLeft(::UnknownApiAccessMethodError)
.mapEmpty()

Expand Down

0 comments on commit 7aff65e

Please sign in to comment.