mirror of
https://github.com/lennart-k/rustical.git
synced 2026-01-30 15:18:22 +00:00
simplify handling of ical-related errors
This commit is contained in:
@@ -26,10 +26,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
||||
}
|
||||
|
||||
let parser = ical::IcalParser::from_slice(body.as_bytes());
|
||||
let mut cal = parser
|
||||
.expect_one()
|
||||
.map_err(rustical_ical::Error::ParserError)?
|
||||
.mutable();
|
||||
let mut cal = parser.expect_one()?.mutable();
|
||||
|
||||
// Extract calendar metadata
|
||||
let displayname = cal
|
||||
@@ -70,12 +67,7 @@ pub async fn route_import<C: CalendarStore, S: SubscriptionStore>(
|
||||
cal_components.push(CalendarObjectType::Todo);
|
||||
}
|
||||
|
||||
let objects = cal
|
||||
.into_objects()
|
||||
.map_err(rustical_ical::Error::ParserError)?
|
||||
.into_iter()
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
let objects = cal.into_objects()?.into_iter().map(Into::into).collect();
|
||||
let new_cal = Calendar {
|
||||
principal,
|
||||
id: cal_id,
|
||||
|
||||
@@ -75,7 +75,8 @@ impl Error {
|
||||
Self::XmlDecodeError(_) => StatusCode::BAD_REQUEST,
|
||||
Self::ChronoParseError(_) | Self::NotImplemented => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::NotFound => StatusCode::NOT_FOUND,
|
||||
Self::IcalError(err) => err.status_code(),
|
||||
// TODO: Can also be Bad Request, if it's used input
|
||||
Self::IcalError(_err) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::PreconditionFailed(_err) => StatusCode::PRECONDITION_FAILED,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user