feat: graceful server unavailability handling in login screen
Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
parent
13e8107f4d
commit
8ceda0c4e6
|
|
@ -38,6 +38,7 @@ import androidx.lifecycle.ViewModel
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.navigation.NavController
|
||||
import chat.revolt.R
|
||||
import chat.revolt.RevoltApplication
|
||||
import chat.revolt.api.REVOLT_SUPPORT
|
||||
import chat.revolt.api.RevoltAPI
|
||||
import chat.revolt.api.routes.account.EmailPasswordAssessment
|
||||
|
|
@ -79,7 +80,14 @@ class LoginViewModel @Inject constructor(
|
|||
_error = null
|
||||
|
||||
viewModelScope.launch {
|
||||
val response = negotiateAuthentication(_email, _password)
|
||||
val response = try {
|
||||
negotiateAuthentication(_email, _password)
|
||||
} catch (e: Exception) {
|
||||
_error = if (e.message?.startsWith("Unexpected JSON token") == true) {
|
||||
RevoltApplication.instance.getString(R.string.service_health_alert_body_default)
|
||||
} else e.message ?: "Unknown error"
|
||||
return@launch
|
||||
}
|
||||
if (response.error != null) {
|
||||
_error = response.error.type
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ import androidx.lifecycle.viewModelScope
|
|||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavController
|
||||
import chat.revolt.R
|
||||
import chat.revolt.RevoltApplication
|
||||
import chat.revolt.api.routes.account.RegistrationBody
|
||||
import chat.revolt.api.routes.account.register
|
||||
import chat.revolt.api.routes.misc.getRootRoute
|
||||
|
|
@ -53,7 +54,14 @@ class RegisterDetailsScreenViewModel : ViewModel() {
|
|||
|
||||
fun initCaptcha(context: Context, onSuccess: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val root = getRootRoute()
|
||||
val root = try {
|
||||
getRootRoute()
|
||||
} catch (e: Exception) {
|
||||
error = if (e.message?.startsWith("Expected response body of the type") == true) {
|
||||
RevoltApplication.instance.getString(R.string.service_health_alert_body_default)
|
||||
} else e.message
|
||||
return@launch
|
||||
}
|
||||
|
||||
if (!root.features.captcha.enabled) {
|
||||
onSuccess()
|
||||
|
|
|
|||
Loading…
Reference in New Issue