Display SDK error message when generating email alias (#1219)

This commit is contained in:
Patrick Honkonen 2024-04-03 17:29:21 -04:00 committed by Álison Fernandes
parent 22a6825992
commit af37f1c03c
4 changed files with 13 additions and 5 deletions

View file

@ -200,7 +200,7 @@ class GeneratorRepositoryImpl(
GeneratedForwardedServiceUsernameResult.Success(generatedEmail)
},
onFailure = {
GeneratedForwardedServiceUsernameResult.InvalidRequest
GeneratedForwardedServiceUsernameResult.InvalidRequest(it.message)
},
)

View file

@ -14,5 +14,5 @@ sealed class GeneratedForwardedServiceUsernameResult {
/**
* There was an error during the operation.
*/
data object InvalidRequest : GeneratedForwardedServiceUsernameResult()
data class InvalidRequest(val message: String?) : GeneratedForwardedServiceUsernameResult()
}

View file

@ -651,8 +651,13 @@ class GeneratorViewModel @Inject constructor(
}
}
GeneratedForwardedServiceUsernameResult.InvalidRequest -> {
sendEvent(GeneratorEvent.ShowSnackbar(R.string.an_error_has_occurred.asText()))
is GeneratedForwardedServiceUsernameResult.InvalidRequest -> {
sendEvent(
GeneratorEvent.ShowSnackbar(
message = result.message?.asText()
?: R.string.an_error_has_occurred.asText(),
),
)
}
}
}

View file

@ -410,7 +410,10 @@ class GeneratorRepositoryTest {
val result = repository.generateForwardedServiceUsername(request)
assertEquals(GeneratedForwardedServiceUsernameResult.InvalidRequest, result)
assertEquals(
GeneratedForwardedServiceUsernameResult.InvalidRequest(exception.message),
result,
)
coVerify { generatorSdkSource.generateForwardedServiceEmail(request) }
}