pref: 无网络错误提示
This commit is contained in:
parent
67052d4a91
commit
618cc74f9c
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue