simplify handling of ical-related errors

This commit is contained in:
Lennart K
2026-01-16 14:16:22 +01:00
parent 2c67890343
commit 63373ad525
7 changed files with 22 additions and 62 deletions

View File

@@ -1,34 +0,0 @@
use axum::{http::StatusCode, response::IntoResponse};
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Error {
#[error("Invalid ics/vcf input: {0}")]
InvalidData(String),
#[error("Missing calendar")]
MissingCalendar,
#[error("Missing contact")]
MissingContact,
#[error(transparent)]
ParserError(#[from] ical::parser::ParserError),
}
impl Error {
#[must_use]
pub const fn status_code(&self) -> StatusCode {
match self {
Self::InvalidData(_) | Self::MissingCalendar | Self::MissingContact => {
StatusCode::BAD_REQUEST
}
Self::ParserError(_) => StatusCode::INTERNAL_SERVER_ERROR,
}
}
}
impl IntoResponse for Error {
fn into_response(self) -> axum::response::Response {
(self.status_code(), self.to_string()).into_response()
}
}

View File

@@ -1,13 +1,13 @@
#![warn(clippy::all, clippy::pedantic, clippy::nursery)]
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
mod timestamp;
use ical::parser::ParserError;
pub use timestamp::*;
mod calendar_object;
pub use calendar_object::*;
mod error;
pub use error::Error;
mod address_object;
pub use address_object::AddressObject;
pub type Error = ParserError;