In Python, I can use marshmallow or Pydantic to validate user input just by defining a schema (much like a Rust struct). Then using that schema, Marshmallow loads the user input and returns the error it finds. Such as:
I can have custom error handle in actix-web by implementing ResponseError
.
But, how can I return the description (position/field of invalid value) in a bad request body to the client?
I am always looking for answers.
Unfortunately, some web frameworks including actix handle JSON error before we can do any validation. I keep searching for using various keywords. One of them is "actix-web validate JSON" which leads me to many validator crates. But I get insight from this blog saying that:
So, I search for "actix Extractor" and bring me Extractor Doc and custom handling of extractor errors
So this snippet is taken from this boilerplate solves my current problem.