https://kotlinlang.org logo
#ktor
Title
n

Nikolai

07/07/2019, 3:30 PM
Hi, everyone I am using ktor for multiplatform and have an issue with 'no internet' case. For Android it's ok, I have an exception. But on iOS platform I see strange behaviour. Here is my code:
Copy code
try {
                val call = client.request<HttpResponse> {
                    url {
                        protocol = serverProtocol
                        host = serverAddress
                        encodedPath = requestEncodedPath
                    }
                    method = HttpMethod.Get
                    body = requestBody

                    for (currentPair:Pair<String, String> in requestHeaders) {
                        headers.append(currentPair.first, currentPair.second)
                    }
                    for (currentPair:Pair<String, String> in parameters) {
                        parameter(currentPair.first, currentPair.second)
                    }
                }
                println("CALL : ${call.content}, ${call.status}, ${call.requestTime}, ${call.responseTime}")
                requestResponseHandler(call, call.readText())
            } catch (requestException:Exception) {
                println("MESSAGE : ${requestException.message}, ${requestException::class.simpleName}")
        
            }
For iOS platform if no internet (wifi and mobile internet) I see exception trace in Xcode, but lines :
Copy code
println("CALL : ${call.content}, ${call.status}, ${call.requestTime}, ${call.responseTime}")
                requestResponseHandler(call, call.readText())
are not called, so I event can't handle this problem. Is it expected behaviour? Here is client setup :
Copy code
private val client = HttpClient {
        expectSuccess = false
        install(JsonFeature) {
            serializer = KotlinxSerializer()
        }
    }