mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-13 12:38:58 +01:00
Ignore non-existent galleries during favorites sync
This commit is contained in:
@@ -10,7 +10,11 @@ import rx.Producer
|
||||
import rx.Subscription
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
fun Call.asObservable(): Observable<Response> {
|
||||
fun Call.asObservableWithAsyncStacktrace(): Observable<Pair<Exception, Response>> {
|
||||
// Record stacktrace at creation time for easier debugging
|
||||
// asObservable is involved in a lot of crashes so this is worth the performance hit
|
||||
val asyncStackTrace = Exception("Async stacktrace")
|
||||
|
||||
return Observable.unsafeCreate { subscriber ->
|
||||
// Since Call is a one-shot type, clone it for each new subscriber.
|
||||
val call = clone()
|
||||
@@ -23,12 +27,12 @@ fun Call.asObservable(): Observable<Response> {
|
||||
try {
|
||||
val response = call.execute()
|
||||
if (!subscriber.isUnsubscribed) {
|
||||
subscriber.onNext(response)
|
||||
subscriber.onNext(asyncStackTrace to response)
|
||||
subscriber.onCompleted()
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
if (!subscriber.isUnsubscribed) {
|
||||
subscriber.onError(error)
|
||||
subscriber.onError(error.withRootCause(asyncStackTrace))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,19 +51,14 @@ fun Call.asObservable(): Observable<Response> {
|
||||
}
|
||||
}
|
||||
|
||||
fun Call.asObservableSuccess(): Observable<Response> {
|
||||
// Record stacktrace at creation time for easier debugging
|
||||
// asObservable is involved in a lot of crashes so this is worth the performance hit
|
||||
val asyncStackTrace = Exception("Async stacktrace")
|
||||
fun Call.asObservable() = asObservableWithAsyncStacktrace().map { it.second }
|
||||
|
||||
return asObservable().doOnNext { response ->
|
||||
fun Call.asObservableSuccess(): Observable<Response> {
|
||||
return asObservableWithAsyncStacktrace().map { (asyncStacktrace, response) ->
|
||||
if (!response.isSuccessful) {
|
||||
response.close()
|
||||
throw Exception("HTTP error ${response.code()}")
|
||||
}
|
||||
}.onErrorReturn {
|
||||
// Set root cause to async stacktrace and throw again
|
||||
throw it.withRootCause(asyncStackTrace)
|
||||
throw Exception("HTTP error ${response.code()}", asyncStacktrace)
|
||||
} else response
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.network.asObservableWithAsyncStacktrace
|
||||
import eu.kanade.tachiyomi.source.model.*
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
import eu.kanade.tachiyomi.source.online.LewdSource
|
||||
@@ -32,6 +33,7 @@ import uy.kohesive.injekt.injectLazy
|
||||
import java.net.URLEncoder
|
||||
import java.util.*
|
||||
import exh.metadata.metadata.base.RaisedTag
|
||||
import java.lang.RuntimeException
|
||||
|
||||
class EHentai(override val id: Long,
|
||||
val exh: Boolean,
|
||||
@@ -236,11 +238,21 @@ class EHentai(override val id: Long,
|
||||
*/
|
||||
override fun fetchMangaDetails(manga: SManga): Observable<SManga> {
|
||||
return client.newCall(mangaDetailsRequest(manga))
|
||||
.asObservableSuccess()
|
||||
.flatMap {
|
||||
parseToManga(manga, it).andThen(Observable.just(manga.apply {
|
||||
initialized = true
|
||||
}))
|
||||
.asObservableWithAsyncStacktrace()
|
||||
.flatMap { (stacktrace, response) ->
|
||||
if(response.isSuccessful) {
|
||||
parseToManga(manga, response).andThen(Observable.just(manga.apply {
|
||||
initialized = true
|
||||
}))
|
||||
} else {
|
||||
response.close()
|
||||
|
||||
if(response.code() == 404) {
|
||||
throw GalleryNotFoundException(stacktrace)
|
||||
} else {
|
||||
throw Exception("HTTP error ${response.code()}", stacktrace)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,6 +534,8 @@ class EHentai(override val id: Long,
|
||||
else
|
||||
"E-Hentai"
|
||||
|
||||
class GalleryNotFoundException(cause: Throwable): RuntimeException("Gallery not found!", cause)
|
||||
|
||||
companion object {
|
||||
private const val QUERY_PREFIX = "?f_apply=Apply+Filter"
|
||||
private const val TR_SUFFIX = "TR"
|
||||
|
||||
Reference in New Issue
Block a user