mirror of
https://github.com/null2264/yokai.git
synced 2025-06-20 18:24:42 +00:00
fix(extension/repo): Don't throw an error if it's a connection error
Fixes GH-130
This commit is contained in:
parent
fb92d1dcb6
commit
9d4dc5f351
6 changed files with 37 additions and 4 deletions
|
@ -0,0 +1,6 @@
|
|||
package yokai.domain.extension.repo.exception
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
class FetchExtensionRepoException(throwable: Throwable) :
|
||||
IOException("Failed to retrieve Extension Repo Details", throwable)
|
|
@ -5,6 +5,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
|
|||
import okhttp3.OkHttpClient
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.extension.repo.ExtensionRepoRepository
|
||||
import yokai.domain.extension.repo.exception.FetchExtensionRepoException
|
||||
import yokai.domain.extension.repo.exception.SaveExtensionRepoException
|
||||
import yokai.domain.extension.repo.model.ExtensionRepo
|
||||
import yokai.domain.extension.repo.service.ExtensionRepoService
|
||||
|
@ -27,7 +28,11 @@ class CreateExtensionRepo(
|
|||
}
|
||||
|
||||
val baseUrl = repoUrl.removeSuffix("/index.min.json")
|
||||
return extensionRepoService.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl
|
||||
return try {
|
||||
extensionRepoService.fetchRepoDetails(baseUrl)?.let { insert(it) } ?: Result.InvalidUrl
|
||||
} catch (e: FetchExtensionRepoException) {
|
||||
Result.RepoFetchFailed
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun insert(repo: ExtensionRepo): Result {
|
||||
|
@ -74,6 +79,7 @@ class CreateExtensionRepo(
|
|||
data class DuplicateFingerprint(val oldRepo: ExtensionRepo, val newRepo: ExtensionRepo) : Result
|
||||
data object InvalidUrl : Result
|
||||
data object RepoAlreadyExists : Result
|
||||
data object RepoFetchFailed : Result
|
||||
data object Success : Result
|
||||
data object Error : Result
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package yokai.domain.extension.repo.interactor
|
||||
|
||||
import co.touchlab.kermit.Logger
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.coroutineScope
|
||||
import yokai.domain.extension.repo.ExtensionRepoRepository
|
||||
import yokai.domain.extension.repo.exception.FetchExtensionRepoException
|
||||
import yokai.domain.extension.repo.model.ExtensionRepo
|
||||
import yokai.domain.extension.repo.service.ExtensionRepoService
|
||||
|
||||
|
@ -21,7 +23,17 @@ class UpdateExtensionRepo(
|
|||
}
|
||||
|
||||
suspend fun await(repo: ExtensionRepo) {
|
||||
val newRepo = extensionRepoService.fetchRepoDetails(repo.baseUrl) ?: return
|
||||
val newRepo = try {
|
||||
extensionRepoService.fetchRepoDetails(repo.baseUrl) ?: return
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is FetchExtensionRepoException -> {
|
||||
Logger.e(e) { "Failed to fetch repo details" }
|
||||
return
|
||||
}
|
||||
else -> throw e
|
||||
}
|
||||
}
|
||||
if (
|
||||
repo.signingKeyFingerprint.startsWith("NOFINGERPRINT") ||
|
||||
repo.signingKeyFingerprint == newRepo.signingKeyFingerprint
|
||||
|
|
|
@ -12,7 +12,9 @@ import kotlinx.serialization.json.jsonObject
|
|||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import okhttp3.OkHttpClient
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import yokai.domain.extension.repo.exception.FetchExtensionRepoException
|
||||
import yokai.domain.extension.repo.model.ExtensionRepo
|
||||
import java.net.UnknownHostException
|
||||
|
||||
class ExtensionRepoService(
|
||||
private val client: OkHttpClient,
|
||||
|
@ -35,8 +37,12 @@ class ExtensionRepoService(
|
|||
response["meta"]
|
||||
?.jsonObject
|
||||
?.let { jsonToExtensionRepo(baseUrl = repo, it) }
|
||||
} catch (_: HttpException) {
|
||||
null
|
||||
} catch (e: Exception) {
|
||||
when (e) {
|
||||
is HttpException -> null
|
||||
is UnknownHostException -> throw FetchExtensionRepoException(e)
|
||||
else -> throw e
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ class ExtensionRepoViewModel :
|
|||
is CreateExtensionRepo.Result.Success -> internalEvent.value = ExtensionRepoEvent.Success
|
||||
is CreateExtensionRepo.Result.Error -> internalEvent.value = ExtensionRepoEvent.InvalidUrl
|
||||
is CreateExtensionRepo.Result.RepoAlreadyExists -> internalEvent.value = ExtensionRepoEvent.RepoAlreadyExists
|
||||
is CreateExtensionRepo.Result.RepoFetchFailed -> internalEvent.value = ExtensionRepoEvent.RepoFetchFailed
|
||||
is CreateExtensionRepo.Result.DuplicateFingerprint -> {
|
||||
internalEvent.value = ExtensionRepoEvent.ShowDialog(RepoDialog.Conflict(result.oldRepo, result.newRepo))
|
||||
}
|
||||
|
@ -93,6 +94,7 @@ sealed class ExtensionRepoEvent {
|
|||
sealed class LocalizedMessage(val stringRes: StringResource) : ExtensionRepoEvent()
|
||||
data object InvalidUrl : LocalizedMessage(MR.strings.invalid_repo_url)
|
||||
data object RepoAlreadyExists : LocalizedMessage(MR.strings.repo_already_exists)
|
||||
data object RepoFetchFailed : LocalizedMessage(MR.strings.repo_fetch_failed)
|
||||
data class ShowDialog(val dialog: RepoDialog) : ExtensionRepoEvent()
|
||||
data object NoOp : ExtensionRepoEvent()
|
||||
data object Success : ExtensionRepoEvent()
|
||||
|
|
|
@ -880,6 +880,7 @@
|
|||
<string name="action_add_repo">Add repo</string>
|
||||
<string name="invalid_repo_url">Invalid repo url</string>
|
||||
<string name="repo_already_exists">Repo already exists!</string>
|
||||
<string name="repo_fetch_failed">Failed to retrieve repo details. Please try again later</string>
|
||||
<string name="information_empty_repos">You haven\'t added any repos yet.</string>
|
||||
<string name="confirm_delete_repo_title">Delete repo?</string>
|
||||
<string name="confirm_delete_repo">Are you sure you wish to delete the repo \"%s\"?</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue