Rename ServerConnectionListener.kt to ApiConnectionListener.kt,
ServerConnectionHandler.kt to ApiConnectionHandler.kt and ServerConnectionException.kt to ApiConnectionException.kt
This commit is contained in:
parent
b69d40f9fb
commit
519765b9bd
|
@ -46,7 +46,7 @@ import me.proton.core.network.domain.NetworkManager
|
|||
import me.proton.core.network.domain.NetworkPrefs
|
||||
import me.proton.core.network.domain.client.ClientIdProvider
|
||||
import me.proton.core.network.domain.client.ExtraHeaderProvider
|
||||
import me.proton.core.network.domain.serverconnection.ServerConnectionListener
|
||||
import me.proton.core.network.domain.serverconnection.ApiConnectionListener
|
||||
import me.proton.core.network.domain.humanverification.HumanVerificationListener
|
||||
import me.proton.core.network.domain.humanverification.HumanVerificationProvider
|
||||
import me.proton.core.network.domain.server.ServerTimeListener
|
||||
|
@ -109,7 +109,7 @@ class NetworkModule {
|
|||
humanVerificationProvider: HumanVerificationProvider,
|
||||
humanVerificationListener: HumanVerificationListener,
|
||||
extraHeaderProvider: ExtraHeaderProvider,
|
||||
serverConnectionListener: ServerConnectionListener
|
||||
apiConnectionListener: ApiConnectionListener
|
||||
): ApiManagerFactory = ApiManagerFactory(
|
||||
Constants.BASE_URL,
|
||||
apiClient,
|
||||
|
@ -131,7 +131,7 @@ class NetworkModule {
|
|||
)
|
||||
},
|
||||
extraHeaderProvider,
|
||||
serverConnectionListener
|
||||
apiConnectionListener
|
||||
)
|
||||
|
||||
@Provides
|
||||
|
@ -141,7 +141,7 @@ class NetworkModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGuestHoleFallbackListener(): ServerConnectionListener = object: ServerConnectionListener {
|
||||
fun provideGuestHoleFallbackListener(): ApiConnectionListener = object: ApiConnectionListener {
|
||||
override suspend fun <T> onPotentiallyBlocked(
|
||||
path: String?,
|
||||
query: String?,
|
||||
|
|
|
@ -37,8 +37,8 @@ import me.proton.core.network.domain.NetworkManager
|
|||
import me.proton.core.network.domain.NetworkPrefs
|
||||
import me.proton.core.network.domain.client.ClientIdProvider
|
||||
import me.proton.core.network.domain.client.ExtraHeaderProvider
|
||||
import me.proton.core.network.domain.serverconnection.ServerConnectionListener
|
||||
import me.proton.core.network.domain.handlers.ServerConnectionHandler
|
||||
import me.proton.core.network.domain.serverconnection.ApiConnectionListener
|
||||
import me.proton.core.network.domain.handlers.ApiConnectionHandler
|
||||
import me.proton.core.network.domain.handlers.HumanVerificationInvalidHandler
|
||||
import me.proton.core.network.domain.handlers.HumanVerificationNeededHandler
|
||||
import me.proton.core.network.domain.handlers.ProtonForceUpdateHandler
|
||||
|
@ -85,7 +85,7 @@ class ApiManagerFactory(
|
|||
private val alternativeApiPins: List<String> = Constants.ALTERNATIVE_API_SPKI_PINS,
|
||||
private val cache: () -> Cache? = { null },
|
||||
private val extraHeaderProvider: ExtraHeaderProvider? = null,
|
||||
private val serverConnectionListener: ServerConnectionListener?
|
||||
private val apiConnectionListener: ApiConnectionListener?
|
||||
) {
|
||||
|
||||
@OptIn(ObsoleteCoroutinesApi::class)
|
||||
|
@ -137,7 +137,7 @@ class ApiManagerFactory(
|
|||
): List<ApiErrorHandler<Api>> {
|
||||
val refreshTokenHandler = RefreshTokenHandler<Api>(sessionId, sessionProvider, sessionListener, monoClockMs)
|
||||
val forceUpdateHandler = ProtonForceUpdateHandler<Api>(apiClient)
|
||||
val serverConnectionHandler = ServerConnectionHandler<Api>(serverConnectionListener)
|
||||
val serverConnectionHandler = ApiConnectionHandler<Api>(apiConnectionListener)
|
||||
val humanVerificationNeededHandler =
|
||||
HumanVerificationNeededHandler<Api>(sessionId, clientIdProvider, humanVerificationListener, monoClockMs)
|
||||
val humanVerificationInvalidHandler =
|
||||
|
|
|
@ -20,7 +20,7 @@ package me.proton.core.network.data
|
|||
import kotlinx.serialization.SerializationException
|
||||
import me.proton.core.network.domain.ApiResult
|
||||
import me.proton.core.network.domain.NetworkManager
|
||||
import me.proton.core.network.domain.exception.ServerConnectionException
|
||||
import me.proton.core.network.domain.exception.ApiConnectionException
|
||||
import me.proton.core.util.kotlin.CoreLogger
|
||||
import okhttp3.Response
|
||||
import retrofit2.HttpException
|
||||
|
@ -46,7 +46,7 @@ internal suspend fun <Api, T> safeApiCall(
|
|||
ApiResult.Error.Parse(e)
|
||||
} catch (e: CertificateException) {
|
||||
ApiResult.Error.Certificate(e)
|
||||
} catch (e: ServerConnectionException) {
|
||||
} catch (e: ApiConnectionException) {
|
||||
e.toApiResult(networkManager)
|
||||
}
|
||||
if (result is ApiResult.Error) {
|
||||
|
@ -55,7 +55,7 @@ internal suspend fun <Api, T> safeApiCall(
|
|||
return result
|
||||
}
|
||||
|
||||
private fun ServerConnectionException.toApiResult(networkManager: NetworkManager): ApiResult.Error.Connection {
|
||||
private fun ApiConnectionException.toApiResult(networkManager: NetworkManager): ApiResult.Error.Connection {
|
||||
// handle the exceptions that might indicate that the API is potentially blocked
|
||||
return when (originalException) {
|
||||
is SSLHandshakeException -> ApiResult.Error.Certificate(this)
|
||||
|
|
|
@ -20,7 +20,7 @@ package me.proton.core.network.data.interceptor
|
|||
|
||||
import me.proton.core.network.data.ProtonErrorException
|
||||
import me.proton.core.network.data.protonApi.ProtonErrorData
|
||||
import me.proton.core.network.domain.exception.ServerConnectionException
|
||||
import me.proton.core.network.domain.exception.ApiConnectionException
|
||||
import me.proton.core.util.kotlin.deserializeOrNull
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
@ -35,7 +35,7 @@ class ServerErrorInterceptor : Interceptor {
|
|||
} catch (e: IOException) {
|
||||
// every IO exception is possible potential blocking of the API
|
||||
with(request.url) {
|
||||
throw ServerConnectionException(encodedPath, query, e)
|
||||
throw ApiConnectionException(encodedPath, query, e)
|
||||
}
|
||||
}
|
||||
if (!response.isSuccessful) {
|
||||
|
|
|
@ -142,6 +142,7 @@ internal class ApiManagerTests {
|
|||
mockk(),
|
||||
scope,
|
||||
cache = { null },
|
||||
apiConnectionListener = null
|
||||
)
|
||||
|
||||
coEvery { dohService.getAlternativeBaseUrls(any()) } returns listOf(proxy1url)
|
||||
|
|
|
@ -166,7 +166,8 @@ internal class HumanVerificationTests {
|
|||
humanVerificationListener,
|
||||
cookieStore,
|
||||
scope,
|
||||
cache = { null }
|
||||
cache = { null },
|
||||
apiConnectionListener = null
|
||||
)
|
||||
every { networkManager.isConnectedToNetwork() } returns isNetworkAvailable
|
||||
|
||||
|
|
|
@ -133,7 +133,8 @@ internal class ProtonApiBackendTests {
|
|||
humanVerificationListener,
|
||||
cookieStore,
|
||||
scope,
|
||||
cache = { null }
|
||||
cache = { null },
|
||||
apiConnectionListener = null
|
||||
)
|
||||
|
||||
every { networkManager.isConnectedToNetwork() } returns isNetworkAvailable
|
||||
|
|
|
@ -20,7 +20,7 @@ package me.proton.core.network.domain
|
|||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import me.proton.core.network.domain.exception.ServerConnectionException
|
||||
import me.proton.core.network.domain.exception.ApiConnectionException
|
||||
import me.proton.core.network.domain.humanverification.HumanVerificationAvailableMethods
|
||||
|
||||
/**
|
||||
|
@ -100,8 +100,8 @@ sealed class ApiResult<out T> {
|
|||
) : Error(cause) {
|
||||
override val isPotentialBlocking get() = potentialBlock
|
||||
|
||||
val path = if (cause is ServerConnectionException) cause.path else null
|
||||
val query = if (cause is ServerConnectionException) cause.query else null
|
||||
val path = if (cause is ApiConnectionException) cause.path else null
|
||||
val query = if (cause is ApiConnectionException) cause.query else null
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,7 +20,7 @@ package me.proton.core.network.domain.exception
|
|||
|
||||
import java.io.IOException
|
||||
|
||||
class ServerConnectionException(
|
||||
class ApiConnectionException(
|
||||
val path: String,
|
||||
val query: String?,
|
||||
val originalException: IOException
|
|
@ -24,10 +24,10 @@ import me.proton.core.network.domain.ApiBackend
|
|||
import me.proton.core.network.domain.ApiErrorHandler
|
||||
import me.proton.core.network.domain.ApiManager
|
||||
import me.proton.core.network.domain.ApiResult
|
||||
import me.proton.core.network.domain.serverconnection.ServerConnectionListener
|
||||
import me.proton.core.network.domain.serverconnection.ApiConnectionListener
|
||||
|
||||
class ServerConnectionHandler<Api>(
|
||||
private val serverConnectionListener: ServerConnectionListener?
|
||||
class ApiConnectionHandler<Api>(
|
||||
private val apiConnectionListener: ApiConnectionListener?
|
||||
) : ApiErrorHandler<Api> {
|
||||
override suspend fun <T> invoke(
|
||||
backend: ApiBackend<Api>,
|
||||
|
@ -37,7 +37,7 @@ class ServerConnectionHandler<Api>(
|
|||
if (!error.isPotentialBlocking) return error
|
||||
if (error !is ApiResult.Error.Connection) return error
|
||||
|
||||
return serverConnectionListener?.let { listener ->
|
||||
return apiConnectionListener?.let { listener ->
|
||||
globalMutex.withLock {
|
||||
listener.onPotentiallyBlocked(error.path, error.query) { backend(call) }
|
||||
}
|
|
@ -20,7 +20,7 @@ package me.proton.core.network.domain.serverconnection
|
|||
|
||||
import me.proton.core.network.domain.ApiResult
|
||||
|
||||
interface ServerConnectionListener {
|
||||
interface ApiConnectionListener {
|
||||
|
||||
suspend fun <T> onPotentiallyBlocked(
|
||||
path: String?,
|
Loading…
Reference in New Issue