-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Http Client Configuration (#786)
* Improve Http Client Configuration * Lint
- Loading branch information
Showing
5 changed files
with
71 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...r/src/main/kotlin/eu/kanade/tachiyomi/network/interceptor/UncaughtExceptionInterceptor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package eu.kanade.tachiyomi.network.interceptor | ||
|
||
import okhttp3.Interceptor | ||
import okhttp3.Response | ||
import java.io.IOException | ||
|
||
/** | ||
* Catches any uncaught exceptions from later in the chain and rethrows as a non-fatal | ||
* IOException to avoid catastrophic failure. | ||
* | ||
* This should be the first interceptor in the client. | ||
* | ||
* See https://square.github.io/okhttp/4.x/okhttp/okhttp3/-interceptor/ | ||
*/ | ||
class UncaughtExceptionInterceptor : Interceptor { | ||
override fun intercept(chain: Interceptor.Chain): Response { | ||
return try { | ||
chain.proceed(chain.request()) | ||
} catch (e: Exception) { | ||
if (e is IOException) { | ||
throw e | ||
} else { | ||
throw IOException(e) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters