I have this function that makes a network request and writes results to SQLDelight database:
@Throws(Exception::class)
suspend fun updateData()
In iOS project in Xcode I see that this function is translated into a function with completionHandler of type (KotlinUnit?, Error?) -> Void
.
In my case Error type has only 1 visible property - localizedDescription
. If I cast to NSError
then I can get more visible fields but none of them are of any help.
I saw in logs that every error in Ktor
http client is thrown as Error
in Swift. This makes it hard to know what kind of error was thrown.
I want to be able to see the error type and react differently for certain cases. For example, if it was network unavailable error, to show my custom error text with translations, or if it was 401 error send user to auth page, 500 show some other text, etc.
For Android app I guess I can just forward those exceptions and still be able to type check or access more data about error. But I don't know what to do for iOS app. The solution ideally should work great on both platforms.
What are the best practices for handling network errors in iOS and in Android or in general any error/exception that are thrown from shared module in multiplatform project?