Consider this simple ktor server setup
@Location("/user") data class User(val id: Long)
fun Application.module(testing: Boolean = false) {
install(Locations)
routing {
get<User> {
call.respondText("User[id: ${id}]")
}
}
}
Getting /user?id=123 works fine resulting in User [id 123].
However getting /user yields HTTP 404 but a HTTP 400 make much more sense here.
How can I
- Serve
400instead of404in such case? - Attach a custom error handler for missing query parameters so I can provide clients with information about what they got wrong?
sidenote: I also filled an issue in the ktor github repository for this.
Thanks in advance!