```post("/oauth/token") { val gt = call.parame...
# ktor
y
Copy code
post("/oauth/token") {
    val gt = call.parameters.get("grant_type") ?: call.respond(HttpStatusCode.BadRequest, mapOf("error" to "no grant_type specified"));
    call.respondText(call.request.headers["Authorization"] ?: "No header")
}
how to response and return to avoid run the second response?
s
Something like this?
Copy code
post("/oauth/token") {
param("grant_type") {
handle {
    val gt = call.parameters.get("grant_type")!! call.respond(HttpStatusCode.BadRequest, mapOf("error" to "no grant_type specified"));
    call.respondText(call.request.headers["Authorization"] ?: "No header")
}
}
}
y
No, I want just want to finish the response if no grant type found.
Thanks, I found the solution:
Copy code
post("/oauth/token") {
    val gt = call.parameters.get("grant_type") ?: run {
        call.respond(
            HttpStatusCode.BadRequest,
            mapOf("error" to "no grant_type specified")
        );
        return@post
    }
    call.respondText(call.request.headers["Authorization"] ?: "No header")
}
d
Why dont you just do
Copy code
if (gt == null) {...}
?
y
to avoid if