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.
This commit is contained in:
funkyhippo 2019-08-19 04:24:50 -07:00 committed by Eugene
parent 4c60142a5b
commit 43ad2d268d
2 changed files with 14 additions and 9 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: Guya'
pkgNameSuffix = "en.guya"
extClass = '.Guya'
extVersionCode = 4
extVersionCode = 5
libVersion = '1.2'
}

View File

@ -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<String> {
@ -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
}