I have a status request in my api for monitoring o...
# ktor
r
I have a status request in my api for monitoring on
/status
, this request can return 500 with a body that gives details. I also have a StatusPages that listens to all generic 500 errors with respondText. The problem is that the StatusPages overrides the response body on my
/status
request. Is there a way to check if there already is a response body in my StatusPages or something?
a
You can check the type of the
content
property within a status handler. Here is an example:
Copy code
install(StatusPages) {
    status(HttpStatusCode.InternalServerError) { code ->
        if (content is HttpStatusCodeContent) {
            call.respondText(status = HttpStatusCode.InternalServerError) { "Error" }
        }
    }
}
routing {
    get("/status") {
        call.respondText(status = HttpStatusCode.InternalServerError) { "Status" }
    }

    get("/") {
        call.respond(HttpStatusCode.InternalServerError)
    }
}