diff --git a/library/src/model/validator.rs b/library/src/model/validator.rs index 23eeace..76a74a3 100644 --- a/library/src/model/validator.rs +++ b/library/src/model/validator.rs @@ -1,7 +1,7 @@ use std::str::FromStr; use i18n::{message, message_ids::MessageId}; -use validator::Validate; +use validator::{Validate, ValidationErrors}; use crate::model::response::{ResData, ResErr, ResResult}; @@ -15,21 +15,11 @@ pub fn validate_params(params: &impl Validate, local: &str) -> ResResult { - for (_field, errs) in err.field_errors() { - for e in errs { - let msg = e.message.clone().unwrap_or_default(); - errors.push(message!(local, MessageId::from_str(msg.trim()).unwrap())); - } - } + pack_error_msg(&mut errors, err, local); }, validator::ValidationErrorsKind::List(err) => { for (_, err) in err.iter() { - for (_field, errs) in err.field_errors() { - for e in errs { - let msg = e.message.clone().unwrap_or_default(); - errors.push(message!(local, MessageId::from_str(msg.trim()).unwrap())); - } - } + pack_error_msg(&mut errors, err, local); } }, validator::ValidationErrorsKind::Field(err) => { @@ -43,4 +33,13 @@ pub fn validate_params(params: &impl Validate, local: &str) -> ResResult, raw_errors: &Box, local: &str) { + for (_field, errs) in raw_errors.field_errors() { + for e in errs { + let msg = e.message.clone().unwrap_or_default(); + errors.push(message!(local, MessageId::from_str(msg.trim()).unwrap())); + } + } } \ No newline at end of file