exception
fun ProblemType.exception(detail: String? = null, instance: String? = null, cause: Throwable? = null): ProblemException(source)
Raises this problem type as a ProblemException.
The throwing twin of ProblemType.problem, with the same per-occurrence parameters. typeUri, title and status come from the type and cannot be overridden per call, because §3.1 asks title to stay constant across occurrences.
For a problem that needs extension members, build the document and wrap it directly: throw ProblemException(problem { type(OutOfCredit); extension("balance", 30) }).
Parameters
detail
human-readable explanation of this occurrence.
instance
URI reference identifying this occurrence. Left unset, problem-details-ktor fills it from the request path.
cause
the underlying failure. Chained and logged, never exposed to the client.
Samples
val outOfCredit =
object : ProblemType {
override val typeUri: String = "https://example.com/probs/out-of-credit"
override val title: String = "You do not have enough credit."
override val status: Int = 403
}
// Thrown from domain code: nothing on this path depends on a web framework. The Ktor
// integration answers it with this document, filling `instance` from the request path.
throw outOfCredit.exception(detail = "Your current balance is 30, but that costs 50.")Content copied to clipboard