Added proper error message for failed auth

This commit is contained in:
Sylvain Berfini 2023-09-19 09:25:35 +02:00
parent 62139047b3
commit 5813c5d9d8
3 changed files with 35 additions and 5 deletions

View file

@ -26,13 +26,16 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R
import org.linphone.core.Account
import org.linphone.core.AuthInfo
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.Factory
import org.linphone.core.Reason
import org.linphone.core.RegistrationState
import org.linphone.core.tools.Log
import org.linphone.utils.AppUtils
import org.linphone.utils.Event
class AccountLoginViewModel @UiThread constructor() : ViewModel() {
@ -82,8 +85,19 @@ class AccountLoginViewModel @UiThread constructor() : ViewModel() {
} else if (state == RegistrationState.Failed) {
registrationInProgress.postValue(false)
core.removeListener(this)
// TODO: show translated string
accountLoginErrorEvent.postValue(Event(message))
val error = when (account.error) {
Reason.Forbidden -> {
AppUtils.getString(R.string.assistant_account_login_forbidden_error)
}
else -> {
AppUtils.getFormattedString(
R.string.assistant_account_login_error,
account.error.toInt()
)
}
}
accountLoginErrorEvent.postValue(Event(error))
Log.e("$TAG Account failed to REGISTER [$message], removing it")
core.removeAuthInfo(newlyCreatedAuthInfo)

View file

@ -26,14 +26,17 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R
import org.linphone.core.Account
import org.linphone.core.AuthInfo
import org.linphone.core.Core
import org.linphone.core.CoreListenerStub
import org.linphone.core.Factory
import org.linphone.core.Reason
import org.linphone.core.RegistrationState
import org.linphone.core.TransportType
import org.linphone.core.tools.Log
import org.linphone.utils.AppUtils
import org.linphone.utils.Event
class ThirdPartySipAccountLoginViewModel @UiThread constructor() : ViewModel() {
@ -93,8 +96,19 @@ class ThirdPartySipAccountLoginViewModel @UiThread constructor() : ViewModel() {
} else if (state == RegistrationState.Failed) {
registrationInProgress.postValue(false)
core.removeListener(this)
// TODO: show translated string
accountLoginErrorEvent.postValue(Event(message))
val error = when (account.error) {
Reason.Forbidden -> {
AppUtils.getString(R.string.assistant_account_login_forbidden_error)
}
else -> {
AppUtils.getFormattedString(
R.string.assistant_account_login_error,
account.error.toInt()
)
}
}
accountLoginErrorEvent.postValue(Event(error))
Log.e("$TAG Account failed to REGISTER [$message], removing it")
core.removeAuthInfo(newlyCreatedAuthInfo)
@ -118,7 +132,7 @@ class ThirdPartySipAccountLoginViewModel @UiThread constructor() : ViewModel() {
loginEnabled.value = isLoginButtonEnabled()
}
// TODO: handle formatting errors
// TODO: handle formatting errors ?
availableTransports.add(UDP)
availableTransports.add(TCP)

View file

@ -129,6 +129,8 @@
<string name="assistant_account_register_server_error">Failed to create account, error %i</string>
<string name="assistant_account_register_push_notification_not_received_error">Push notification with auth token not received in 5 seconds, please try again later</string>
<string name="assistant_account_register_unexpected_error">Unexpected error occurred, please try again later</string>
<string name="assistant_account_login_forbidden_error">Wrong username or password</string>
<string name="assistant_account_login_error">Failed to login: error code is %i</string>
<string name="drawer_menu_manage_account">Manage the profile</string>
<string name="drawer_menu_account_connection_status_connected">Connected</string>