From 618cc74f9ca06d6cb57eabc00ac52146b12fed67 Mon Sep 17 00:00:00 2001 From: HuanCheng65 <22636177+HuanCheng65@users.noreply.github.com> Date: Mon, 17 Jul 2023 13:31:36 +0800 Subject: [PATCH] =?UTF-8?q?pref:=20=E6=97=A0=E7=BD=91=E7=BB=9C=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/retrofit/interceptors/ConnectivityInterceptor.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interceptors/ConnectivityInterceptor.kt b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interceptors/ConnectivityInterceptor.kt index d22e8c4f..7768b301 100644 --- a/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interceptors/ConnectivityInterceptor.kt +++ b/app/src/main/java/com/huanchengfly/tieba/post/api/retrofit/interceptors/ConnectivityInterceptor.kt @@ -7,6 +7,7 @@ import com.huanchengfly.tieba.post.utils.isNetworkConnected import okhttp3.Interceptor import okhttp3.Response import java.io.IOException +import java.net.SocketException import java.net.SocketTimeoutException object ConnectivityInterceptor : Interceptor { @@ -16,16 +17,16 @@ object ConnectivityInterceptor : Interceptor { val exception = response.exceptionOrNull() return when { + (exception is SocketTimeoutException || exception is SocketException) && isNetworkConnected() -> throw NoConnectivityException( + App.INSTANCE.getString(R.string.connectivity_timeout) + ) + exception is IOException && !isNetworkConnected() -> throw NoConnectivityException( App.INSTANCE.getString( R.string.no_internet_connectivity ) ) - exception is SocketTimeoutException && isNetworkConnected() -> throw NoConnectivityException( - App.INSTANCE.getString(R.string.connectivity_timeout) - ) - else -> response.getOrThrow() } }