Hello, I know this question already been discussed...
# ktor
a
Hello, I know this question already been discussed here: https://kotlinlang.slack.com/archives/C0A974TJ9/p1618316707270300 but I am still having some concerns over there. Also will be great to get more deep understanding of how it is handled. So... when I execute get request on iOS and something went wrong (4xx error codes) app crashes with exception:
Copy code
Exception doesn't match @Throws-specified class list and thus isn't propagated from Kotlin to Objective-C/Swift as NSError.
It is considered unexpected and unhandled instead. Program will be terminated.
As potential solution it was proposed to use
expectSuccess = false
However, there are some more use-cases where my request/response might fail (for instance serialization). I am wondering if there are any best practices about error handling on ios. Currently I wrap my request with try catch and convert any exception I receive from ktor with CancellationException which can be understood and converted to NSError, but not 100% sure this is correct.
Copy code
try {
            return httpClient.getSomething()
        } catch (cancellationException: CancellationException) {
            throw cancellationException
        } catch (exception: Exception) {
            throw CancellationException(cause = exception)
        }