I'm seeing a strange issue when using supabase-kt ...
# supabase-kt
c
I'm seeing a strange issue when using supabase-kt on iOS. When the device is offline, any request made to the Postgrest plugin causes a hard crash with the following exception:
Copy code
io.ktor.client.engine.darwin.DarwinHttpRequestException: Exception in http request: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline."
I've tried a simple try/catch around this and it still doesn't seem to catch the error. Has anyone experienced this before? I can't be the first person, but not finding much help online. I've simplified this down to as little as this, to try and isolate from anything else that might be interfering:
Copy code
try {
                db.from(TABLE_USER)
                    .select {
                        filter { eq(FIELD_ID, userId) }
                    }
                    .decodeSingle<User>()
            } catch (t: Throwable) {
                Logger.d("SplashViewModel") { "Caught throwable - $t" }
            }
But still seeing this happen here only in iOS and not other platforms
interestingly, I do see the log statement print
Caught throwable io.github.jan.supabase.exceptions.HttpRequestException
but something else seems to be throwing this
DarwinHttpRequestException
that I can't workout where its coming from
j
The caught error is from supabase yea, I looked online and some have the same problem with uncatchable exceptions in ktor. A few fixed it by catching throwables (what you are doing) or CoroutineExceptionHandler. Maybe worth a try.
👍🏼 1
c
thanks! Only thing I can find on ktor is this which seems related but is from 2019 and very out of date; and allegedly fixed. Sadly a CoroutineExceptionHandler doesn't solve the issue 😞
interestingly, when I interact directly with KTOR, the exception does get caught in my catch block and that app doesnt crash:
Copy code
class Greeting {
    private val client = HttpClient()

    suspend fun greeting(): String {
        return try {
            client.get("<https://ktor.io/docs/>")
                .bodyAsText()
        } catch (t: Throwable) {
            "Failed to fetch - ${t.message}"
        }
    }
}
I've kicked off a new project and isolated this to a single function:
Copy code
suspend fun greeting(): String {
        return try {
            supabaseClient.postgrest.from("outlet")
                .select()
                .decodeAs<String>()
        } catch (t: Throwable) {
            "Failed to fetch - ${t.message}"
        }
    }
This is not crashing and the exception is being caught. So there must be other complexities in my project that are causing problems. I'll keep digging further to investigate where I'm going wrong, but think we can consider this an issue on my end 🙂
okay found the issue, I have an app delegate on iOS thats interacting with supabase to update the users fcm token when this changes. This is triggering on app launch, and no error handling was implemented