1.2.0
IOS Client
iOS - Airplane mode
Tried to catch offline mode exception in case the internet connection is dropped. The errors showed up in the logs but cannot be caught in Multiplatform common project. Haven't tried on Android yet.
2019-06-03 16:02:17.432609+0800 XApp[1558:1117673] Task <449DDD76-DA3D-42B4-9CA4-ECEA0B218850>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={_kCFStreamErrorCodeKey=50, NSUnderlyingError=0x282e59d40 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <449DDD76-DA3D-42B4-9CA4-ECEA0B218850>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <449DDD76-DA3D-42B4-9CA4-ECEA0B218850>.<1>"
), NSLocalizedDescription=The Internet connection appears to be offline., NSErrorFailingURLStringKey=https://localhost/?page=1&ordering=modified&search=, NSErrorFailingURLKey=https://localhost/?page=1&ordering=modified&search=, _kCFStreamErrorDomainKey=1} [-1009]
I have the same problem, @LiewJunTung how did you catch this exception?
In Android is working fine, but in IOS crashes, seems a problem of IosClientEngine and the delegate protocol.
@tonilopezmr for now I'm not handling it. And will wait for the fix by @e5l. :)
I had the same problem. But I've solved it by catching a Throwable instead of an Exception in the try/catch block.
Hope it helps.
I think I was catching it with Throwable as well 馃 I'll try another time
I am experiencing the same problem, catching Throwable instead of Exception did not work for me.
This only happens in release mode. Also true for you guys?
Throwable works nice for me, but the problem I have is that I show the "Default error". Is there any way to know what error is?, I'm doing something like this:
```kotlin
private suspend fun
try {
Either.Right(f())
} catch (e: Throwable) {
print(e.toString())
Either.Left(
when (e) {
is ClientRequestException -> when (e.response.status) {
HttpStatusCode.Unauthorized -> Error.InvalidCredentials
HttpStatusCode.NotFound -> Error.NotFound
else -> Error.Default
}
else -> Error.Default
}
)
}
Should be fixed in 1.3.0. Could you please verify?
Hello @cy6erGn0m , which should be the exception type? ClientRequestException?
Another workaround is to use CoroutineExceptionHandler
Same issue here with android. I get a "java.net.UnknownHostException" when there's no internet connection (eg: airplane mode) which is of course only available on jvm, so I can't catch it on the common side. I think it should be possible to handle the exception on the platform specific side, but I'd like to know if that's just a "temporary workaround" or it is the desired behaviour
i think reason of error is this line - https://github.com/ktorio/ktor/blob/63c508918543774b857977ad033d602e04491dc4/ktor-client/ktor-client-ios/darwin/src/io/ktor/client/engine/ios/IosUtils.kt#L40
IosHttpRequestException not Exception but just Throwable. it's reason why we not catch this Exception when use catch(e: Exception) and why catch(e: Throwable) will help.
i think this case should be Exception, not just Throwable.
@e5l Yes, it's more reasonable that IosHttpRequestException is an Exception.
@e5l when it's going to be released the fix?
Most helpful comment
I have the same problem, @LiewJunTung how did you catch this exception?
In Android is working fine, but in IOS crashes, seems a problem of
IosClientEngineand the delegate protocol.