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

Nikky

02/25/2022, 2:29 AM
trying to use ktor-server on kotlin-native.. got everything i care about working .. but StatusPages seems to not work the callbacks for handling exceptions get executed.. but
call.respondText(text = cause.message, status = HttpStatusCode.InternalServerError)
seems to not trigger a http response and the request is just hanging
a

Aleksei Tirman [JB]

02/25/2022, 8:03 AM
I cannot reproduce it with the following code:
Copy code
embeddedServer(CIO, port = 4444) {
    install(StatusPages) {
        exception { call, cause: Throwable ->
            call.respondText(text = cause.message!!, status = HttpStatusCode.InternalServerError)
        }
    }

    routing {
        get("/") {
            throw Exception("some error")
        }
    }
}.start(wait = true)
Could you please share a code snippet?
n

Nikky

02/25/2022, 10:54 AM
i think it happened because i was using
call.respondBytesWriter {}
and passing the write channel to some function.. in there it might throw.. i restructured to code to instead return a
Memory
and feed that into the write channel now it works
i must have been too tired yesterday 😛
3 Views