From 43ad2d268dd125fb9c0f4afcf53511cc6e307613 Mon Sep 17 00:00:00 2001 From: funkyhippo <52957110+funkyhippo@users.noreply.github.com> Date: Mon, 19 Aug 2019 04:24:50 -0700 Subject: [PATCH] Fail the fetch without crashing the entire app, also added fallback behaviour. (#1404) Fail the fetch without crashing the entire app, also added fallback behaviour. --- src/en/guya/build.gradle | 2 +- .../tachiyomi/extension/en/guya/Guya.kt | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/en/guya/build.gradle b/src/en/guya/build.gradle index 80a05ac0f..2c6112b63 100644 --- a/src/en/guya/build.gradle +++ b/src/en/guya/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: Guya' pkgNameSuffix = "en.guya" extClass = '.Guya' - extVersionCode = 4 + extVersionCode = 5 libVersion = '1.2' } diff --git a/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt b/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt index 6d84b1531..62c65f77f 100644 --- a/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt +++ b/src/en/guya/src/eu/kanade/tachiyomi/extension/en/guya/Guya.kt @@ -297,14 +297,15 @@ open class Guya() : ConfigurableSource, HttpSource() { return key } } - - throw Exception("Cannot find scanlator group!") + // Fall back to value as key if endpoint fails + return value } fun getValueFromKey(key: String): String { update() + // Fallback to key as value if endpoint fails return if (!scanlatorMap[key].isNullOrEmpty()) - scanlatorMap[key].toString() else "No info" + scanlatorMap[key].toString() else key } fun keys(): MutableSet { @@ -318,11 +319,15 @@ open class Guya() : ConfigurableSource, HttpSource() { clientBuilder().newCall(GET(scanlatorCacheUrl, headers)).enqueue( object: Callback { override fun onResponse(call: Call, response: Response) { - val json = JSONObject(response.body()!!.string()) - val iter = json.keys() - while (iter.hasNext()) { - val scanId = iter.next() - scanlatorMap[scanId] = json.getString(scanId) + try { + val json = JSONObject(response.body()!!.string()) + val iter = json.keys() + while (iter.hasNext()) { + val scanId = iter.next() + scanlatorMap[scanId] = json.getString(scanId) + } + } catch (e: Exception) { + // ScanlatorStore will fall back to using keys until update() succeeds } polling = false }