problemsFrom
Documents the part of catalog that is true of every operation.
That means the catch-all — every unmapped failure still answers with a problem document — and one response per status registered through forStatusCode, standardStatusCodes() included. Those hold wherever this is applied, so applying it at the routing root documents an entire application honestly.
Types declared through map<T>(type) are deliberately left out. A catalog is installed once for the whole application and records no route, so attaching them everywhere would document GET /health as returning 403 and make client generators emit handling for it. Name them where they occur with problemResponse, or, if a subtree really can produce all of them, iterate catalog.problemTypes yourself.
A mapping written as a lambda contributes nothing beyond the catch-all: it produces its document at call time and has no type to read.
Samples
val catalog =
problemCatalog {
standardStatusCodes()
map<IllegalStateException>(OutOfCredit)
}
install(StatusPages) { problemDetails(catalog) }
routing {
describe {
// The catch-all and the four standard status codes: true of every route below.
responses { problemsFrom(catalog) }
}
get("/orders/{id}") {
call.respondText("an order")
}.describe {
// `OutOfCredit` is named here, where it can actually occur, rather than everywhere.
responses { problemResponse(OutOfCredit) }
}
}