Open DerkSchooltink opened 6 years ago
FWIW, if you wanted one place, it seems like it can always be retrieved from the subject as OutgoingContent
after the Render
phase:
/**
* Phase to render any current pipeline subject into [io.ktor.http.content.OutgoingContent]
*
* Beyond this phase only [io.ktor.http.content.OutgoingContent] should be produced by any interceptor
*/
val Render = PipelinePhase("Render")
The caveat is that it can still be null
if no status code was provided in a respond(...)
(as in, doesn't get defaulted to 200).
That said, this information feels like it certainly should be available in the response
API.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Given the following code:
call.respond(HttpStatusCode.InternalServerError, "{}")
call.respondText("{}", ContentType.Application.Json, HttpStatusCode.InternalServerError)
I am intercepting the response in the 'after' of the 'sendPipeline':
The results for this interceptor are as following:
ApplicationResponse#status()
TextContent#status
call.respond(HttpStatusCode.InternalServerError, "{}")
500 Internal Server Error
null
call.respondText("{}", ContentType.Application.Json, HttpStatusCode.InternalServerError)
null
500 Internal Server Error
Perhaps it is logical that usecase 1 has a null value for
TextContent#status
because it is not an actualTextContent
. However, I would expect for usecase 2 thatApplicationResponse#status()
would be set.tl;dr: There is no single source of truth for getting the statuscode (which I would expect to be
ApplicationResponse#status()
.