We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I would love if there would be more documentation about error handlers available. The only thing I found was this comment
For example I went with this:
use actix_web_validator::error::flatten_errors; use serde::Serialize; use serde_json::Value; use std::collections::HashMap; #[derive(Serialize)] pub struct ValidationErrorJsonPayload { pub message: String, pub fields: Vec<FieldError>, } #[derive(Serialize)] pub struct FieldError { pub field_name: String, pub params: HashMap<String, Value>, } impl From<&validator::ValidationErrors> for ValidationErrorJsonPayload { fn from(error: &validator::ValidationErrors) -> Self { let errors = flatten_errors(error); let mut field_errors: Vec<FieldError> = Vec::new(); for (index, field, error) in errors { field_errors.insert( index as usize, FieldError { field_name: field, params: error.params.clone().into_iter().map(|(key, value)| (key.into_owned(), value)).collect(), }, ) } ValidationErrorJsonPayload { message: "Validation error".to_owned(), fields: field_errors, } } }
WIth this setup the actual error is getting returned
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I would love if there would be more documentation about error handlers available.
The only thing I found was this comment
For example I went with this:
WIth this setup the actual error is getting returned
The text was updated successfully, but these errors were encountered: