mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 23:51:21 +02:00
Fix error reporting & crash during Jellyseerr login (#802)
## Description Makes sure the invalid credentials error is propagated up instead of displaying "No URL" as the error message. Makes sure `OkHttp` is initialized since the startup initialization provider is disabled. This fixes a possible crash if `OkHttp` needs to access its assets. Also, shows the URL when removing the Jellyseerr server.
This commit is contained in:
parent
003fe8348c
commit
3ada35c731
3 changed files with 8 additions and 3 deletions
|
|
@ -10,6 +10,7 @@ import androidx.compose.runtime.ExperimentalComposeRuntimeApi
|
||||||
import androidx.hilt.work.HiltWorkerFactory
|
import androidx.hilt.work.HiltWorkerFactory
|
||||||
import androidx.work.Configuration
|
import androidx.work.Configuration
|
||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
|
import okhttp3.OkHttp
|
||||||
import org.acra.ACRA
|
import org.acra.ACRA
|
||||||
import org.acra.ReportField
|
import org.acra.ReportField
|
||||||
import org.acra.config.dialog
|
import org.acra.config.dialog
|
||||||
|
|
@ -63,6 +64,7 @@ class WholphinApplication :
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
OkHttp.initialize(this)
|
||||||
initAcra {
|
initAcra {
|
||||||
buildConfigClass = BuildConfig::class.java
|
buildConfigClass = BuildConfig::class.java
|
||||||
reportFormat = StringFormat.JSON
|
reportFormat = StringFormat.JSON
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,7 @@ fun PreferencesContent(
|
||||||
val state = rememberLazyListState()
|
val state = rememberLazyListState()
|
||||||
var preferences by remember { mutableStateOf(initialPreferences) }
|
var preferences by remember { mutableStateOf(initialPreferences) }
|
||||||
val currentUser by viewModel.currentUser.observeAsState()
|
val currentUser by viewModel.currentUser.observeAsState()
|
||||||
|
val currentServer by seerrVm.currentSeerrServer.collectAsState(null)
|
||||||
var showPinFlow by remember { mutableStateOf(false) }
|
var showPinFlow by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val navDrawerPins by viewModel.navDrawerPins.observeAsState(mapOf())
|
val navDrawerPins by viewModel.navDrawerPins.observeAsState(mapOf())
|
||||||
|
|
@ -481,7 +482,7 @@ fun PreferencesContent(
|
||||||
SeerrDialogMode.Remove -> {
|
SeerrDialogMode.Remove -> {
|
||||||
ConfirmDialog(
|
ConfirmDialog(
|
||||||
title = stringResource(R.string.remove_seerr_server),
|
title = stringResource(R.string.remove_seerr_server),
|
||||||
body = "",
|
body = currentServer?.url ?: "",
|
||||||
onCancel = { seerrDialogMode = SeerrDialogMode.None },
|
onCancel = { seerrDialogMode = SeerrDialogMode.None },
|
||||||
onConfirm = {
|
onConfirm = {
|
||||||
seerrVm.removeServer()
|
seerrVm.removeServer()
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ class SwitchSeerrViewModel
|
||||||
private val serverRepository: ServerRepository,
|
private val serverRepository: ServerRepository,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
val currentUser = serverRepository.currentUser
|
val currentUser = serverRepository.currentUser
|
||||||
|
val currentSeerrServer = seerrServerRepository.currentServer
|
||||||
|
|
||||||
val serverConnectionStatus = MutableStateFlow<LoadingState>(LoadingState.Pending)
|
val serverConnectionStatus = MutableStateFlow<LoadingState>(LoadingState.Pending)
|
||||||
|
|
||||||
|
|
@ -61,15 +62,16 @@ class SwitchSeerrViewModel
|
||||||
passwordOrApiKey = passwordOrApiKey,
|
passwordOrApiKey = passwordOrApiKey,
|
||||||
)
|
)
|
||||||
} catch (ex: ClientException) {
|
} catch (ex: ClientException) {
|
||||||
Timber.w(ex, "Error logging in")
|
Timber.w(ex, "ClientException logging in")
|
||||||
if (ex.statusCode == 401 || ex.statusCode == 403) {
|
if (ex.statusCode == 401 || ex.statusCode == 403) {
|
||||||
showToast(context, "Invalid credentials")
|
showToast(context, "Invalid credentials")
|
||||||
LoadingState.Error("Invalid credentials", ex)
|
result = LoadingState.Error("Invalid credentials", ex)
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
LoadingState.Error("Could not connect with URL")
|
LoadingState.Error("Could not connect with URL")
|
||||||
}
|
}
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
|
Timber.w(ex, "Exception logging in")
|
||||||
LoadingState.Error(ex)
|
LoadingState.Error(ex)
|
||||||
}
|
}
|
||||||
if (result is LoadingState.Success) {
|
if (result is LoadingState.Success) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue