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:
parent
4c60142a5b
commit
43ad2d268d
|
@ -5,7 +5,7 @@ ext {
|
||||||
appName = 'Tachiyomi: Guya'
|
appName = 'Tachiyomi: Guya'
|
||||||
pkgNameSuffix = "en.guya"
|
pkgNameSuffix = "en.guya"
|
||||||
extClass = '.Guya'
|
extClass = '.Guya'
|
||||||
extVersionCode = 4
|
extVersionCode = 5
|
||||||
libVersion = '1.2'
|
libVersion = '1.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,14 +297,15 @@ open class Guya() : ConfigurableSource, HttpSource() {
|
||||||
return key
|
return key
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Fall back to value as key if endpoint fails
|
||||||
throw Exception("Cannot find scanlator group!")
|
return value
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getValueFromKey(key: String): String {
|
fun getValueFromKey(key: String): String {
|
||||||
update()
|
update()
|
||||||
|
// Fallback to key as value if endpoint fails
|
||||||
return if (!scanlatorMap[key].isNullOrEmpty())
|
return if (!scanlatorMap[key].isNullOrEmpty())
|
||||||
scanlatorMap[key].toString() else "No info"
|
scanlatorMap[key].toString() else key
|
||||||
}
|
}
|
||||||
|
|
||||||
fun keys(): MutableSet<String> {
|
fun keys(): MutableSet<String> {
|
||||||
|
@ -318,11 +319,15 @@ open class Guya() : ConfigurableSource, HttpSource() {
|
||||||
clientBuilder().newCall(GET(scanlatorCacheUrl, headers)).enqueue(
|
clientBuilder().newCall(GET(scanlatorCacheUrl, headers)).enqueue(
|
||||||
object: Callback {
|
object: Callback {
|
||||||
override fun onResponse(call: Call, response: Response) {
|
override fun onResponse(call: Call, response: Response) {
|
||||||
val json = JSONObject(response.body()!!.string())
|
try {
|
||||||
val iter = json.keys()
|
val json = JSONObject(response.body()!!.string())
|
||||||
while (iter.hasNext()) {
|
val iter = json.keys()
|
||||||
val scanId = iter.next()
|
while (iter.hasNext()) {
|
||||||
scanlatorMap[scanId] = json.getString(scanId)
|
val scanId = iter.next()
|
||||||
|
scanlatorMap[scanId] = json.getString(scanId)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// ScanlatorStore will fall back to using keys until update() succeeds
|
||||||
}
|
}
|
||||||
polling = false
|
polling = false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue