feat(auth): use typed PasswordResetException in ForgotPasswordViewModel

This commit is contained in:
null 2026-07-01 01:50:36 -05:00
parent 885af0b9e4
commit 79bfea7cfb
1 changed files with 5 additions and 3 deletions

View File

@ -3,6 +3,7 @@ package app.closer.ui.auth
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import app.closer.domain.repository.AuthRepository import app.closer.domain.repository.AuthRepository
import app.closer.domain.repository.PasswordResetException
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
@ -46,9 +47,10 @@ class ForgotPasswordViewModel @Inject constructor(
} }
} }
private fun friendlyError(e: Throwable): String = when { private fun friendlyError(e: Throwable): String = when (e) {
e.message?.contains("no user record") == true -> "No account found with that email." is PasswordResetException.NoAccount -> "No account found with that email."
e.message?.contains("badly formatted") == true -> "Please enter a valid email address." 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." else -> e.message ?: "Something went wrong. Please try again."
} }
} }