Skip to content

Commit

Permalink
Enables setting custom messages in complex custom validation functions (
Browse files Browse the repository at this point in the history
#279)

Co-authored-by: decryphe <noreply@github.com>
  • Loading branch information
2 people authored and Keats committed Mar 4, 2024
1 parent 956391c commit 9519689
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions validator/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ impl ValidationError {
pub fn add_param<T: Serialize>(&mut self, name: Cow<'static, str>, val: &T) {
self.params.insert(name, to_value(val).unwrap());
}

/// Adds a custom message to a `ValidationError` that will be used when displaying the
/// `ValidationError`, instead of an auto-generated description.
pub fn with_message(mut self, message: Cow<'static, str>) -> ValidationError {
self.message = Some(message);
self
}
}

impl std::error::Error for ValidationError {
Expand Down

0 comments on commit 9519689

Please sign in to comment.