fix: more network stuffs
This commit is contained in:
parent
e32bfa0cfa
commit
deda67a070
2 changed files with 28 additions and 17 deletions
|
@ -5,6 +5,7 @@ import ani.dantotsu.download.DownloadedType
|
|||
import ani.dantotsu.download.DownloadsManager
|
||||
import ani.dantotsu.parsers.SubtitleType
|
||||
import ani.dantotsu.snackString
|
||||
import ani.dantotsu.util.Logger
|
||||
import com.anggrayudi.storage.file.openOutputStream
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -19,6 +20,7 @@ class SubtitleDownloader {
|
|||
//doesn't really download the subtitles -\_(o_o)_/-
|
||||
suspend fun loadSubtitleType(url: String): SubtitleType =
|
||||
withContext(Dispatchers.IO) {
|
||||
return@withContext try {
|
||||
// Initialize the NetworkHelper instance. Replace this line based on how you usually initialize it
|
||||
val networkHelper = Injekt.get<NetworkHelper>()
|
||||
val request = Request.Builder()
|
||||
|
@ -38,9 +40,13 @@ class SubtitleDownloader {
|
|||
else -> SubtitleType.SRT
|
||||
}
|
||||
|
||||
return@withContext subtitleType
|
||||
subtitleType
|
||||
} else {
|
||||
return@withContext SubtitleType.UNKNOWN
|
||||
SubtitleType.UNKNOWN
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.log(e)
|
||||
SubtitleType.UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package eu.kanade.tachiyomi.network.interceptor
|
||||
|
||||
import ani.dantotsu.util.Logger
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import java.io.IOException
|
||||
import java.net.SocketTimeoutException
|
||||
|
||||
/**
|
||||
* Catches any uncaught exceptions from later in the chain and rethrows as a non-fatal
|
||||
|
@ -17,6 +19,9 @@ class UncaughtExceptionInterceptor : Interceptor {
|
|||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
return try {
|
||||
chain.proceed(chain.request())
|
||||
} catch (e: SocketTimeoutException) {
|
||||
Logger.log(e)
|
||||
throw IOException("Request timed out") // there's some odd behavior throwing a SocketTimeoutException
|
||||
} catch (e: Exception) {
|
||||
if (e is IOException) {
|
||||
throw e
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue