Error handler now returns a string instead (closes #10)
Commit hook now properly returns status code on failed formatting
This commit is contained in:
parent
64161ddcda
commit
6af5368a87
4 changed files with 20 additions and 7 deletions
|
|
@ -14,33 +14,34 @@ const BASE_URL: &str = "https://www.ivago.be/nl/particulier/afval/ophaling";
|
|||
const CAL_URL: &str = "https://www.ivago.be/nl/particulier/garbage/pick-up/pickups";
|
||||
|
||||
/// Represents a very simple Timezoneless date. Considering the timezone will
|
||||
/// always be CEST (aka Belgium's timezone), this is good enough.
|
||||
/// always be CEST (aka Belgium's timezone), this is good enough. I use this
|
||||
/// instead of a NaiveDate to avoid E0117.
|
||||
pub struct BasicDate {
|
||||
year: u32,
|
||||
month: u8,
|
||||
day: u8,
|
||||
}
|
||||
|
||||
/// This allows us to use BasicDate as a query parameter in our routes.
|
||||
impl<'v> FromFormValue<'v> for BasicDate {
|
||||
type Error = &'v RawStr;
|
||||
|
||||
fn from_form_value(form_value: &'v RawStr) -> Result<BasicDate, Self::Error> {
|
||||
// Beautiful how this exact example is in the docs
|
||||
match BasicDate::try_from(form_value.as_str()) {
|
||||
Err(_) => Err(form_value),
|
||||
// Here, we can assume these parses will work, because the regex
|
||||
// didn't fail
|
||||
Ok(date) => Ok(date),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// We need this when deserializing BasicDate.
|
||||
impl ToString for BasicDate {
|
||||
fn to_string(&self) -> String {
|
||||
format!("{}-{}-{}", self.year, self.month, self.day)
|
||||
}
|
||||
}
|
||||
|
||||
/// This is used to serialize BasicDate.
|
||||
impl TryFrom<&str> for BasicDate {
|
||||
type Error = ();
|
||||
|
||||
|
|
@ -49,8 +50,6 @@ impl TryFrom<&str> for BasicDate {
|
|||
|
||||
match re.captures(s) {
|
||||
None => Err(()),
|
||||
// Here, we can assume these parses will work, because the regex
|
||||
// didn't fail
|
||||
Some(caps) => Ok(BasicDate {
|
||||
year: caps.get(1).unwrap().as_str().parse().unwrap(),
|
||||
month: caps.get(2).unwrap().as_str().parse().unwrap(),
|
||||
|
|
@ -74,6 +73,9 @@ impl From<BasicDate> for i64 {
|
|||
// Timezone of Brussels is UTC + 2 hours in the western hemisphere
|
||||
FixedOffset::west(7_200)
|
||||
.ymd(date.year as i32, date.month as u32, date.day as u32)
|
||||
// For some reason, I couldn't get .timestamp() to work on a Date
|
||||
// without a time component, even though the docs seemed to
|
||||
// indicate this was possible
|
||||
.and_hms(0, 0, 0)
|
||||
.timestamp()
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue