pub struct ValidationError {
pub code: Cow<'static, str>,
pub message: Option<Cow<'static, str>>,
pub params: HashMap<Cow<'static, str>, Value>,
pub list_error: Option<Vec<Option<String>>>,
}Fields§
§code: Cow<'static, str>§message: Option<Cow<'static, str>>§params: HashMap<Cow<'static, str>, Value>§list_error: Option<Vec<Option<String>>>Implementations§
Source§impl ValidationError
impl ValidationError
Sourcepub const INTERNAL_CODE: &'static str = "__internal__"
pub const INTERNAL_CODE: &'static str = "__internal__"
Code used by ValidationError::internal.
pub fn new(code: &'static str) -> ValidationError
Sourcepub fn internal(error: impl Display) -> ValidationError
pub fn internal(error: impl Display) -> ValidationError
An error that is not the client’s fault (e.g. a database lookup inside a custom validator
failed). The code is __internal__ and the message is error’s Display text.
web-core turns validation results containing such an error into a 500
(something_went_wrong!) instead of a 400 field-validation error.
use web_core_validator::ValidationError;
let err = ValidationError::internal("connection refused");
assert!(err.is_internal());
assert_eq!(err.message.as_deref(), Some("connection refused"));Sourcepub fn is_internal(&self) -> bool
pub fn is_internal(&self) -> bool
Whether this error was created with ValidationError::internal.
pub fn add_param<T: Serialize>(&mut self, name: Cow<'static, str>, val: &T)
Sourcepub fn with_message(self, message: Cow<'static, str>) -> ValidationError
pub fn with_message(self, message: Cow<'static, str>) -> ValidationError
Adds a custom message to a ValidationError that will be used when displaying the
ValidationError, instead of an auto-generated description.
Trait Implementations§
Source§impl Clone for ValidationError
impl Clone for ValidationError
Source§impl Debug for ValidationError
impl Debug for ValidationError
Source§impl<'de> Deserialize<'de> for ValidationError
impl<'de> Deserialize<'de> for ValidationError
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 ValidationError
impl Display for ValidationError
Source§impl Error for ValidationError
impl Error for ValidationError
Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§fn cause(&self) -> Option<&dyn Error>
fn cause(&self) -> Option<&dyn Error>
👎Deprecated since 1.33.0:
replaced by Error::source, which can support downcasting
Source§impl PartialEq for ValidationError
impl PartialEq for ValidationError
Source§impl Serialize for ValidationError
impl Serialize for ValidationError
impl StructuralPartialEq for ValidationError
Auto Trait Implementations§
impl Freeze for ValidationError
impl RefUnwindSafe for ValidationError
impl Send for ValidationError
impl Sync for ValidationError
impl Unpin for ValidationError
impl UnsafeUnpin for ValidationError
impl UnwindSafe for ValidationError
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> ValidateIp for Twhere
T: ToString,
impl<T> ValidateIp for Twhere
T: ToString,
Source§fn validate_ipv4(&self) -> bool
fn validate_ipv4(&self) -> bool
Validates whether the given string is an IP V4
Source§fn validate_ipv6(&self) -> bool
fn validate_ipv6(&self) -> bool
Validates whether the given string is an IP V6
Source§fn validate_ip(&self) -> bool
fn validate_ip(&self) -> bool
Validates whether the given string is an IP