pub struct VldServerError {
pub message: String,
pub fields: Vec<FieldError>,
}Expand description
Structured, serializable validation error for server functions.
Fields§
§message: StringSummary message.
fields: Vec<FieldError>Per-field validation errors.
Implementations§
Source§impl VldServerError
impl VldServerError
Sourcepub fn validation(fields: Vec<FieldError>) -> Self
pub fn validation(fields: Vec<FieldError>) -> Self
Create a validation error from a list of field errors.
Sourcepub fn field_error(&self, field: &str) -> Option<&str>
pub fn field_error(&self, field: &str) -> Option<&str>
Get the first error message for a specific field.
Sourcepub fn field_errors(&self, field: &str) -> Vec<&str>
pub fn field_errors(&self, field: &str) -> Vec<&str>
Get all error messages for a specific field.
Sourcepub fn has_field_error(&self, field: &str) -> bool
pub fn has_field_error(&self, field: &str) -> bool
Check if a specific field has errors.
Sourcepub fn error_fields(&self) -> Vec<&str>
pub fn error_fields(&self) -> Vec<&str>
List all field names that have errors (unique, in first-seen order).
Sourcepub fn from_json(s: &str) -> Option<Self>
pub fn from_json(s: &str) -> Option<Self>
Parse a VldServerError from a JSON string (e.g. from a ServerFnError message).
Sourcepub fn from_server_message(s: &str) -> Option<Self>
pub fn from_server_message(s: &str) -> Option<Self>
Parse a VldServerError out of a server-function error message.
Leptos / Dioxus ServerFnError’s Display prefixes the message
("error running server function: {...}"), so from_json
on e.to_string() never matches; this reads the JSON object from the
first { to the last }.
use vld_integration_common::form::{FieldError, VldServerError};
let e = VldServerError::validation(vec![FieldError { field: "name".into(), message: "too short".into() }]);
let shown = format!("error running server function: {e}");
let back = VldServerError::from_server_message(&shown).unwrap();
assert_eq!(back.field_error("name"), Some("too short"));Trait Implementations§
Source§impl Clone for VldServerError
impl Clone for VldServerError
Source§impl Debug for VldServerError
impl Debug for VldServerError
Source§impl<'de> Deserialize<'de> for VldServerError
impl<'de> Deserialize<'de> for VldServerError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for VldServerError
impl Display for VldServerError
Source§impl Error for VldServerError
impl Error for VldServerError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl From<VldError> for VldServerError
impl From<VldError> for VldServerError
Source§impl PartialEq for VldServerError
impl PartialEq for VldServerError
Source§impl Serialize for VldServerError
impl Serialize for VldServerError
impl StructuralPartialEq for VldServerError
Auto Trait Implementations§
impl Forget for VldServerError
impl Freeze for VldServerError
impl RefUnwindSafe for VldServerError
impl Send for VldServerError
impl Sync for VldServerError
impl Unpin for VldServerError
impl UnsafeUnpin for VldServerError
impl UnwindSafe for VldServerError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more