Skip to content

Commit 3934bc9

Browse files
PM-19314: Propagate remaining auth errors to the UI (#4888)
1 parent 72c9149 commit 3934bc9

File tree

26 files changed

+139
-58
lines changed

26 files changed

+139
-58
lines changed

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/AuthRepositoryImpl.kt

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ class AuthRepositoryImpl(
775775
override suspend fun requestOneTimePasscode(): RequestOtpResult =
776776
accountsService.requestOneTimePasscode()
777777
.fold(
778-
onFailure = { RequestOtpResult.Error(it.message) },
778+
onFailure = { RequestOtpResult.Error(message = it.message, error = it) },
779779
onSuccess = { RequestOtpResult.Success },
780780
)
781781

@@ -785,29 +785,35 @@ class AuthRepositoryImpl(
785785
passcode = oneTimePasscode,
786786
)
787787
.fold(
788-
onFailure = { VerifyOtpResult.NotVerified(it.message) },
788+
onFailure = { VerifyOtpResult.NotVerified(errorMessage = it.message, error = it) },
789789
onSuccess = { VerifyOtpResult.Verified },
790790
)
791791

792792
override suspend fun resendVerificationCodeEmail(): ResendEmailResult =
793793
resendEmailRequestJson
794794
?.let { jsonRequest ->
795795
accountsService.resendVerificationCodeEmail(body = jsonRequest).fold(
796-
onFailure = { ResendEmailResult.Error(message = it.message) },
796+
onFailure = { ResendEmailResult.Error(message = it.message, error = it) },
797797
onSuccess = { ResendEmailResult.Success },
798798
)
799799
}
800-
?: ResendEmailResult.Error(message = null)
800+
?: ResendEmailResult.Error(
801+
message = null,
802+
error = MissingPropertyException("Resend Email Request"),
803+
)
801804

802805
override suspend fun resendNewDeviceOtp(): ResendEmailResult =
803806
resendNewDeviceOtpRequestJson
804807
?.let { jsonRequest ->
805808
accountsService.resendNewDeviceOtp(body = jsonRequest).fold(
806-
onFailure = { ResendEmailResult.Error(message = it.message) },
809+
onFailure = { ResendEmailResult.Error(message = it.message, error = it) },
807810
onSuccess = { ResendEmailResult.Success },
808811
)
809812
}
810-
?: ResendEmailResult.Error(message = null)
813+
?: ResendEmailResult.Error(
814+
message = null,
815+
error = MissingPropertyException("Resend New Device OTP Request"),
816+
)
811817

812818
override fun switchAccount(userId: String): SwitchAccountResult {
813819
val currentUserState = authDiskSource.userState ?: return SwitchAccountResult.NoChange
@@ -1196,7 +1202,7 @@ class AuthRepositoryImpl(
11961202
verifiedOrganizationDomainSsoDetails = it.verifiedOrganizationDomainSsoDetails,
11971203
)
11981204
},
1199-
onFailure = { VerifiedOrganizationDomainSsoDetailsResult.Failure },
1205+
onFailure = { VerifiedOrganizationDomainSsoDetailsResult.Failure(error = it) },
12001206
)
12011207

12021208
override suspend fun prevalidateSso(
@@ -1315,10 +1321,12 @@ class AuthRepositoryImpl(
13151321
.userState
13161322
?.activeAccount
13171323
?.profile
1318-
?: return ValidatePinResult.Error
1324+
?: return ValidatePinResult.Error(error = NoActiveUserException())
13191325
val pinProtectedUserKey = authDiskSource
13201326
.getPinProtectedUserKey(userId = activeAccount.userId)
1321-
?: return ValidatePinResult.Error
1327+
?: return ValidatePinResult.Error(
1328+
error = MissingPropertyException("Pin Protected User Key"),
1329+
)
13221330
return vaultSdkSource
13231331
.validatePin(
13241332
userId = activeAccount.userId,
@@ -1327,7 +1335,7 @@ class AuthRepositoryImpl(
13271335
)
13281336
.fold(
13291337
onSuccess = { ValidatePinResult.Success(isValid = it) },
1330-
onFailure = { ValidatePinResult.Error },
1338+
onFailure = { ValidatePinResult.Error(error = it) },
13311339
)
13321340
}
13331341

@@ -1353,17 +1361,18 @@ class AuthRepositoryImpl(
13531361
onSuccess = {
13541362
when (it) {
13551363
is SendVerificationEmailResponseJson.Invalid -> {
1356-
SendVerificationEmailResult.Error(it.message)
1364+
SendVerificationEmailResult.Error(
1365+
errorMessage = it.message,
1366+
error = null,
1367+
)
13571368
}
13581369

13591370
is SendVerificationEmailResponseJson.Success -> {
13601371
SendVerificationEmailResult.Success(it.emailVerificationToken)
13611372
}
13621373
}
13631374
},
1364-
onFailure = {
1365-
SendVerificationEmailResult.Error(null)
1366-
},
1375+
onFailure = { SendVerificationEmailResult.Error(errorMessage = null, error = it) },
13671376
)
13681377

13691378
override suspend fun validateEmailToken(email: String, token: String): EmailTokenResult {

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/RequestOtpResult.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ sealed class RequestOtpResult {
1313
/**
1414
* Represents a failure to send the one-time passcode.
1515
*/
16-
data class Error(val message: String?) : RequestOtpResult()
16+
data class Error(
17+
val message: String?,
18+
val error: Throwable,
19+
) : RequestOtpResult()
1720
}

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/ResendEmailResult.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ sealed class ResendEmailResult {
1313
/**
1414
* There was an error.
1515
*/
16-
data class Error(val message: String?) : ResendEmailResult()
16+
data class Error(
17+
val message: String?,
18+
val error: Throwable,
19+
) : ResendEmailResult()
1720
}

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/SendVerificationEmailResult.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ sealed class SendVerificationEmailResult {
1818
*
1919
* @param errorMessage a message describing the error.
2020
*/
21-
data class Error(val errorMessage: String?) : SendVerificationEmailResult()
21+
data class Error(
22+
val errorMessage: String?,
23+
val error: Throwable?,
24+
) : SendVerificationEmailResult()
2225
}

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/UserFingerprintResult.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ sealed class UserFingerprintResult {
1414
/**
1515
* There was an error getting the user fingerprint.
1616
*/
17-
data object Error : UserFingerprintResult()
17+
data class Error(
18+
val error: Throwable,
19+
) : UserFingerprintResult()
1820
}

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/ValidatePinResult.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ sealed class ValidatePinResult {
1414
/**
1515
* There was an error determining if the validity of the PIN.
1616
*/
17-
data object Error : ValidatePinResult()
17+
data class Error(
18+
val error: Throwable,
19+
) : ValidatePinResult()
1820
}

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/VerifiedOrganizationDomainSsoDetailsResult.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ sealed class VerifiedOrganizationDomainSsoDetailsResult {
1818
/**
1919
* The request failed.
2020
*/
21-
data object Failure : VerifiedOrganizationDomainSsoDetailsResult()
21+
data class Failure(
22+
val error: Throwable,
23+
) : VerifiedOrganizationDomainSsoDetailsResult()
2224
}

app/src/main/java/com/x8bit/bitwarden/data/auth/repository/model/VerifyOtpResult.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,8 @@ sealed class VerifyOtpResult {
1313
/**
1414
* Represents a failure to verify the one-time passcode.
1515
*/
16-
data class NotVerified(val errorMessage: String?) : VerifyOtpResult()
16+
data class NotVerified(
17+
val errorMessage: String?,
18+
val error: Throwable,
19+
) : VerifyOtpResult()
1720
}

app/src/main/java/com/x8bit/bitwarden/data/platform/repository/SettingsRepositoryImpl.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.x8bit.bitwarden.data.auth.repository.util.policyInformation
1010
import com.x8bit.bitwarden.data.autofill.accessibility.manager.AccessibilityEnabledManager
1111
import com.x8bit.bitwarden.data.autofill.manager.AutofillEnabledManager
1212
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
13+
import com.x8bit.bitwarden.data.platform.error.NoActiveUserException
1314
import com.x8bit.bitwarden.data.platform.manager.PolicyManager
1415
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
1516
import com.x8bit.bitwarden.data.platform.repository.model.BiometricsKeyResult
@@ -380,12 +381,13 @@ class SettingsRepositoryImpl(
380381
}
381382

382383
override suspend fun getUserFingerprint(): UserFingerprintResult {
383-
val userId = activeUserId ?: return UserFingerprintResult.Error
384+
val userId = activeUserId
385+
?: return UserFingerprintResult.Error(error = NoActiveUserException())
384386

385387
return vaultSdkSource
386388
.getUserFingerprint(userId)
387389
.fold(
388-
onFailure = { UserFingerprintResult.Error },
390+
onFailure = { UserFingerprintResult.Error(error = it) },
389391
onSuccess = { UserFingerprintResult.Success(it) },
390392
)
391393
}

app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/startregistration/StartRegistrationScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ fun StartRegistrationScreen(
134134
BitwardenBasicDialog(
135135
title = dialog.title?.invoke(),
136136
message = dialog.message(),
137+
throwable = dialog.error,
137138
onDismissRequest = remember(viewModel) {
138139
{ viewModel.trySendAction(ErrorDialogDismiss) }
139140
},

0 commit comments

Comments
 (0)