with API
inline fun StatusPagesConfig.withAPI(api: OpenAPIGen, crossinline cfg: OpenAPIGenStatusPagesInterop.() -> Unit = {})(source)
Wraps StatusPages.Configuration to enable OpenAPI configuration for exception handling.
val api = install(OpenAPIGen) { ... }
...
// StatusPage interop, can also define exceptions per-route
install(StatusPages) {
withAPI(api) {
exception<JsonMappingException, Error>(HttpStatusCode.BadRequest) {
it.printStackTrace()
Error("mapping.json", it.localizedMessage)
}
exception<ProperException, Error>(HttpStatusCode.BadRequest) {
it.printStackTrace()
Error(it.id, it.localizedMessage)
}
}
}
Content copied to clipboard
Parameters
api
the installed instance of OpenAPIGen in the io.ktor.application.Application
cfg
the block that loads the configuration, see OpenAPIGenStatusPagesInterop