I'm using this crate by way of axum_extra::extract. The deserialization fails if an html form is submitted with the wrong type, say age=twenty. This causes the extractor to fail and we never get the original form data so we can show the user the errors. What is the pattern to handle this? Currently I am maintaining one extractor form where all fields are Option String, so the form can be extracted regardless of input, and then building a second validation struct with the real field types to maintain the original submitted data and build error messages. This works but is not elegant. Any advice on the approach welcome.
#[derive(Debug, PartialEq, Deserialize)]
struct Form {
one: u8,
two: u8,
}
fn main() {
match serde_html_form::from_str::<Form>("one=1&two=to&three=3") {
Ok(parsed) => {
assert_eq!(parsed, Form { one: 1, two: 2 });
}
Err(e) => {
println!("Error: {}", e);
// --> Error: invalid digit found in string
// where is the rest?
}
};
}
Hi,
I'm using this crate by way of axum_extra::extract. The deserialization fails if an html form is submitted with the wrong type, say age=twenty. This causes the extractor to fail and we never get the original form data so we can show the user the errors. What is the pattern to handle this? Currently I am maintaining one extractor form where all fields are Option String, so the form can be extracted regardless of input, and then building a second validation struct with the real field types to maintain the original submitted data and build error messages. This works but is not elegant. Any advice on the approach welcome.