refactor: simplify code
This commit is contained in:
@@ -89,15 +89,16 @@ impl std::fmt::Display for ContactError {
|
|||||||
/// If no specific field can be identified, returns a generic `ValidationError`.
|
/// If no specific field can be identified, returns a generic `ValidationError`.
|
||||||
impl From<ValidationErrors> for ContactError {
|
impl From<ValidationErrors> for ContactError {
|
||||||
fn from(value: ValidationErrors) -> Self {
|
fn from(value: ValidationErrors) -> Self {
|
||||||
if validator::ValidationErrors::has_error(&Err(value.clone()), "name") {
|
let errors = value.field_errors();
|
||||||
|
if errors.contains_key("name") {
|
||||||
return Self::ValidationNameError("backend.contact.errors.validation.name".to_owned());
|
return Self::ValidationNameError("backend.contact.errors.validation.name".to_owned());
|
||||||
}
|
}
|
||||||
if validator::ValidationErrors::has_error(&Err(value.clone()), "email") {
|
if errors.contains_key("email") {
|
||||||
return Self::ValidationEmailError(
|
return Self::ValidationEmailError(
|
||||||
"backend.contact.errors.validation.email".to_owned(),
|
"backend.contact.errors.validation.email".to_owned(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if validator::ValidationErrors::has_error(&Err(value), "message") {
|
if errors.contains_key("message") {
|
||||||
return Self::ValidationMessageError(
|
return Self::ValidationMessageError(
|
||||||
"backend.contact.errors.validation.message".to_owned(),
|
"backend.contact.errors.validation.message".to_owned(),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user