StatusPages, you need to include the
ktor-server-status-pages artifact in the build script:
To install the
StatusPages plugin, pass it to the
install function in the application initialization code. Depending on the way used to create a server, this can be the
embeddedServer function call ...
... or a specified module.
There are three main configuration options provided by the
exceptions: configures a response based on mapped exception classes
status: configures a response to a status code value
statusFile: configures a file response from the classpath
exception handler allows you to handle calls that result in a
Throwable exception. In the most basic case, the
500 HTTP status code can be configured for any exception:
You can also check specific exceptions and respond with the required content:
status handler provides the capability to respond with specific content based on the status code. The example below shows how to respond on requests if the resource is missing on a server (the
404 status code):
statusFile handler allows you to serve HTML pages based on the status code. Suppose your project contains the
error402.html HTML pages in the
resources folder. In this case, you can handle the
402 status codes using
statusFile as follows:
statusFile handler replaces any
# character with the value of the status code within the list of configured statuses.