Which approach best handles field-level error reporting with Request Validation?
0 reputation · 07 Nov 2021, 18:19 UTC
Ktor's Request Validation plugin allows for the definition of custom validation logic that triggers a RequestValidationException when constraints are violated. While this effectively prevents invalid data from reaching the routing handlers, the default exception mechanism is designed for general request rejection.
When integrating this with the StatusPages plugin, the goal is to return a structured response that identifies exactly which fields failed validation and why, rather than a generic 400 Bad Request. Since the plugin does not provide built-in annotation-based validation, developers must manually define the logic and the associated error metadata.
What is the recommended pattern for passing detailed, field-specific validation failures from the validate block through the RequestValidationException to a StatusPages handler? Does Ktor support a standard way to encapsulate multiple validation errors within a single request lifecycle?