I believe that Ktor always returns a status code. ...
# ktor
k
I believe that Ktor always returns a status code. Is there a way to get the finalized status code? When using
on(ResponseSent)
, the status is nullable:
Copy code
on(ResponseSent) { call ->
  call.response.status() // => HttpStatusCode?
a
You will get the finalized status code in the handler for the
ResponseSent
hook. Ktor doesn't store the sent status code in another object.
k
You will get the finalized status code in the handler for the
ResponseSent
hook.
Could you share some sample code, please?
a
The code you shared should work as expected.
k
Is there a way to reliably obtain a non-null, finalized status code?
a
Does the
call.response.status()
call return null for your use case?
k
No, Ktor has never returned null. However, I don’t understand why it’s defined as nullable.
a
It's because the status code can be set in the
ApplicationResponse
at any point until the response is sent.
❤️ 1