mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-27 15:30:31 +05:30
Better login/register error messages
This commit is contained in:
parent
933cff7ae6
commit
c673b7464b
@ -7,13 +7,17 @@ import android.widget.Toast
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.R
|
||||
import com.github.libretube.api.JsonHelper
|
||||
import com.github.libretube.api.RetrofitInstance
|
||||
import com.github.libretube.api.obj.Login
|
||||
import com.github.libretube.api.obj.Token
|
||||
import com.github.libretube.databinding.DialogLoginBinding
|
||||
import com.github.libretube.extensions.TAG
|
||||
import com.github.libretube.helpers.PreferenceHelper
|
||||
import com.github.libretube.util.TextUtils
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import retrofit2.HttpException
|
||||
|
||||
class LoginDialog(
|
||||
private val onLogin: () -> Unit
|
||||
@ -76,6 +80,12 @@ class LoginDialog(
|
||||
} else {
|
||||
RetrofitInstance.authApi.login(login)
|
||||
}
|
||||
} catch (e: HttpException) {
|
||||
val errorMessage = e.response()?.errorBody()?.string()?.let {
|
||||
JsonHelper.json.decodeFromString<Token>(it).error
|
||||
} ?: context?.getString(R.string.server_error) ?: ""
|
||||
Toast.makeText(context, errorMessage, Toast.LENGTH_SHORT).show()
|
||||
return@launchWhenCreated
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG(), e.toString())
|
||||
Toast.makeText(context, e.localizedMessage, Toast.LENGTH_SHORT).show()
|
||||
|
Loading…
x
Reference in New Issue
Block a user