problemDetails
Registers a ProblemDetailsCatalog against Ktor's own StatusPages configuration.
Each catalog entry becomes one exception(...)/status(...) registration and nothing more: the library generates the calls a developer would otherwise hand-write, so dispatch stays Ktor's.
Samples
install(ContentNegotiation) { problemJson() }
install(StatusPages) {
problemDetails {
// 404, 405 and the rest of Ktor's own status responses become problem documents.
standardStatusCodes()
map<OrderNotFound> { _, cause ->
problem {
type = "https://example.com/probs/order-not-found"
status = 404
title = "Order not found."
detail = "No order ${cause.id} exists."
}
}
// Anything not mapped above, including exceptions thrown by other plugins.
onUnmapped { _, _ ->
problem {
status = 500
title = "Internal Server Error"
}
}
// Runs on every problem this catalog produces, regardless of which mapping built it.
customize { call, problem ->
val traceId = call.request.headers["traceparent"] ?: return@customize problem
problem.copy(extensions = problem.extensions + ("traceId" to ProblemPrimitive(traceId)))
}
}
}Content copied to clipboard
Registers an already-built catalog against Ktor's own StatusPages configuration.
The counterpart of problemCatalog: build the catalog once, install it here and hand the same value to whatever else needs to read it.