Hello all :smiley:. What is the best way to handle...
# ktor
r
Hello all 😃. What is the best way to handle validation errors in Ktor? In spring I used the @ControllerAdvice and @ExceptionHandler (). But I'm a little lost here
d
Add an early pipeline handler and respond to the call with your status code/message
👍 1
r
But if I have a form with the following field: name last name phone And each field has its validation, with its message (minimum number of characters, can not be null, etc). Do I add to the pipeline validation, and will I have the return of every error? Example: The user has filled in all fields in the wrong way: status code 400 { { field: name message: Can not be null } { field: last name message: Can not be null } { field: phone message: Can not be null } }
d
That's up to you
Probably doesn't need to be so detailed
r
Thx @Dico. I got something close to what I wanted using Yavi.
c
Maybe worth a look for you https://github.com/tyntec/ktor-problem . It provides a consistent pattern for error responses. In Java with Spring I used a similar library that catches the validation errors and translated them into a RFC7807 compatible object.