tapir
tapir copied to clipboard
Validation error response - lack of access to the name of the invalid field
I want to return the following response on the validation error:
{
"errors":{
"fieldName": [
"field error"
]
}
}
(like in https://realworld-docs.netlify.app/docs/specs/backend-specs/error-handling#errors-and-status-codes)
I've tried to modify the response handler here: https://github.com/softwaremill/tapir/blob/master/server/core/src/main/scala/sttp/tapir/server/interceptor/decodefailure/DecodeFailureHandler.scala#L33
But the response handler doesn't have access to the field name (only to status code, headers, and error message - (StatusCode, List[Header], String) => ValuedEndpointOutput[_].
I had to write custom DecodeFailureHandler to handle this case -> https://github.com/gothinkster/realworld-starter-kit/blob/de63406311a4e977ab4076132359a5b7bdd5bf69/src/main/scala/com/softwaremill/realworld/CustomDecodeFailureHandler.scala#L39