Fix tests.

This commit is contained in:
dkadrikj 2021-11-17 14:20:10 +01:00 committed by Dino Kadrikj
parent 42e8d4e55b
commit 7421141d26
2 changed files with 7 additions and 13 deletions

View File

@ -46,14 +46,6 @@ internal suspend fun <Api, T> safeApiCall(
ApiResult.Error.Parse(e)
} catch (e: CertificateException) {
ApiResult.Error.Certificate(e)
} catch (e: SSLHandshakeException) {
ApiResult.Error.Certificate(e)
} catch (e: SSLPeerUnverifiedException) {
ApiResult.Error.Certificate(e)
} catch (e: SocketTimeoutException) {
ApiResult.Error.Timeout(networkManager.isConnectedToNetwork(), e)
} catch (e: UnknownHostException) {
ApiResult.Error.NoInternet(e)
} catch (e: NetworkException) {
e.parse(networkManager)
}
@ -65,10 +57,12 @@ internal suspend fun <Api, T> safeApiCall(
private fun NetworkException.parse(networkManager: NetworkManager): ApiResult.Error.Connection {
// handle the exceptions that might indicate that the API is potentially blocked
return if (originalException is SocketTimeoutException) {
ApiResult.Error.Timeout(networkManager.isConnectedToNetwork(), originalException)
} else {
ApiResult.Error.Connection(networkManager.isConnectedToNetwork(), originalException)
return when (originalException) {
is SSLHandshakeException -> ApiResult.Error.Certificate(originalException)
is SSLPeerUnverifiedException -> ApiResult.Error.Certificate(originalException)
is SocketTimeoutException -> ApiResult.Error.Timeout(networkManager.isConnectedToNetwork(), originalException)
is UnknownHostException -> ApiResult.Error.NoInternet(originalException)
else -> ApiResult.Error.Connection(networkManager.isConnectedToNetwork(), originalException)
}
}

View File

@ -35,7 +35,7 @@ class ServerErrorInterceptor : Interceptor {
chain.proceed(request)
} catch (e: IOException) {
// every IO exception is possible potential blocking of the API
with (request.url) {
with(request.url) {
throw NetworkException(encodedPath, query, e)
}
}