You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe I'm missing something, but it seems there is no out-of-the box way to validate incoming requests.
The only thing I can find regarding validation is model-validation, but not request validation.
There is the JsonRejection error that's thrown (when the Json does not comply with the struct used in the controller) which is returned to the user as 400 "Bad Request".
It feels like src/controller/mod.rs#L185 is missing a 422 ValidationError case as well as a few other http errors.
Am I missing something? Is there a way to validate request data and is there a way to abort into other http errors from the controller (like 403 forbidden or even just a 201 no content)?
The text was updated successfully, but these errors were encountered:
So, I've been playing around with this but it seems the error system leaves a bit to be desired.
I'm willing to put some time and effort into developing the following:
Make it possible to throw a CustomError containing Json instead of a plain string and make it so a CustomError can be thrown a bit more easily.
I'd like to add a ValidationError that wraps the ValidationErrors from the validator crate, which when thrown, is returned to the user as a 422 error with the corresponding json as the content.
I want to add a simple Valid type that you can use to wrap Json<SomeStruct>, which when used makes sure your struct is validated using the validator crate before the controller function is called. If the data is invalid, the above ValidationError is thrown and the controller function is not called. Using the type will be optional, you can manually call validate() and convert the error using 2.
Now, before I put in the time to do this, I'd like to make sure you're interested.
If you're interested, give me a go-ahead and I'll get started.
I think I can keep this question short.
Maybe I'm missing something, but it seems there is no out-of-the box way to validate incoming requests.
The only thing I can find regarding validation is model-validation, but not request validation.
There is the JsonRejection error that's thrown (when the Json does not comply with the struct used in the controller) which is returned to the user as 400 "Bad Request".
It feels like src/controller/mod.rs#L185 is missing a 422 ValidationError case as well as a few other http errors.
Am I missing something? Is there a way to validate request data and is there a way to abort into other http errors from the controller (like 403 forbidden or even just a 201 no content)?
The text was updated successfully, but these errors were encountered: