pref: 无网络错误提示

This commit is contained in:
HuanCheng65 2023-07-17 13:31:36 +08:00
parent 67052d4a91
commit 618cc74f9c
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
1 changed files with 5 additions and 4 deletions

View File

@ -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()
}
}