feat(auth): use typed PasswordResetException in ForgotPasswordViewModel
This commit is contained in:
parent
885af0b9e4
commit
79bfea7cfb
|
|
@ -3,6 +3,7 @@ package app.closer.ui.auth
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import app.closer.domain.repository.AuthRepository
|
||||
import app.closer.domain.repository.PasswordResetException
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
|
@ -46,9 +47,10 @@ class ForgotPasswordViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun friendlyError(e: Throwable): String = when {
|
||||
e.message?.contains("no user record") == true -> "No account found with that email."
|
||||
e.message?.contains("badly formatted") == true -> "Please enter a valid email address."
|
||||
private fun friendlyError(e: Throwable): String = when (e) {
|
||||
is PasswordResetException.NoAccount -> "No account found with that email."
|
||||
is PasswordResetException.InvalidEmail -> "Please enter a valid email address."
|
||||
// AuthRateLimiterException (and any other) carry their own user-facing message.
|
||||
else -> e.message ?: "Something went wrong. Please try again."
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue