mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 10:32:19 +00:00
work on errors
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
use actix_web::http::Method;
|
use actix_web::http::Method;
|
||||||
use actix_web::web::{self, Data};
|
use actix_web::web::{self, Data};
|
||||||
use actix_web::{guard, HttpResponse, Responder};
|
use actix_web::{guard, HttpResponse, Responder};
|
||||||
use error::Error;
|
|
||||||
use resources::calendar::CalendarResource;
|
use resources::calendar::CalendarResource;
|
||||||
use resources::event::EventResource;
|
use resources::event::EventResource;
|
||||||
use resources::principal::PrincipalCalendarsResource;
|
use resources::principal::PrincipalCalendarsResource;
|
||||||
@@ -9,12 +8,12 @@ use resources::root::RootResource;
|
|||||||
use routes::propfind::route_propfind;
|
use routes::propfind::route_propfind;
|
||||||
use routes::{calendar, event};
|
use routes::{calendar, event};
|
||||||
use rustical_auth::CheckAuthentication;
|
use rustical_auth::CheckAuthentication;
|
||||||
|
use rustical_dav::error::Error;
|
||||||
use rustical_store::calendar::CalendarStore;
|
use rustical_store::calendar::CalendarStore;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
pub mod error;
|
|
||||||
pub mod resources;
|
pub mod resources;
|
||||||
pub mod routes;
|
pub mod routes;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use actix_web::{web::Data, HttpRequest};
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use rustical_auth::AuthInfo;
|
use rustical_auth::AuthInfo;
|
||||||
|
use rustical_dav::error::Error;
|
||||||
use rustical_dav::{
|
use rustical_dav::{
|
||||||
resource::Resource,
|
resource::Resource,
|
||||||
xml_snippets::{HrefElement, TextNode},
|
xml_snippets::{HrefElement, TextNode},
|
||||||
@@ -174,7 +175,7 @@ impl<C: CalendarStore + ?Sized> Resource for CalendarResource<C> {
|
|||||||
_auth_info: AuthInfo,
|
_auth_info: AuthInfo,
|
||||||
uri_components: Self::UriComponents,
|
uri_components: Self::UriComponents,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
) -> Result<Self> {
|
) -> Result<Self, Error> {
|
||||||
let cal_store = req
|
let cal_store = req
|
||||||
.app_data::<Data<RwLock<C>>>()
|
.app_data::<Data<RwLock<C>>>()
|
||||||
.ok_or(anyhow!("no calendar store in app_data!"))?
|
.ok_or(anyhow!("no calendar store in app_data!"))?
|
||||||
@@ -182,7 +183,13 @@ impl<C: CalendarStore + ?Sized> Resource for CalendarResource<C> {
|
|||||||
.into_inner();
|
.into_inner();
|
||||||
|
|
||||||
let (principal, cid) = uri_components;
|
let (principal, cid) = uri_components;
|
||||||
let calendar = cal_store.read().await.get_calendar(&cid).await?;
|
// TODO: fix errors
|
||||||
|
let calendar = cal_store
|
||||||
|
.read()
|
||||||
|
.await
|
||||||
|
.get_calendar(&cid)
|
||||||
|
.await
|
||||||
|
.map_err(|_e| Error::NotFound)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
cal_store,
|
cal_store,
|
||||||
calendar,
|
calendar,
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use actix_web::{web::Data, HttpRequest};
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use rustical_auth::AuthInfo;
|
use rustical_auth::AuthInfo;
|
||||||
|
use rustical_dav::error::Error;
|
||||||
use rustical_dav::{resource::Resource, xml_snippets::TextNode};
|
use rustical_dav::{resource::Resource, xml_snippets::TextNode};
|
||||||
use rustical_store::calendar::CalendarStore;
|
use rustical_store::calendar::CalendarStore;
|
||||||
use rustical_store::event::Event;
|
use rustical_store::event::Event;
|
||||||
@@ -53,7 +54,7 @@ impl<C: CalendarStore + ?Sized> Resource for EventResource<C> {
|
|||||||
_auth_info: AuthInfo,
|
_auth_info: AuthInfo,
|
||||||
uri_components: Self::UriComponents,
|
uri_components: Self::UriComponents,
|
||||||
_prefix: String,
|
_prefix: String,
|
||||||
) -> Result<Self> {
|
) -> Result<Self, Error> {
|
||||||
let (_principal, cid, uid) = uri_components;
|
let (_principal, cid, uid) = uri_components;
|
||||||
|
|
||||||
let cal_store = req
|
let cal_store = req
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use actix_web::{web::Data, HttpRequest};
|
|||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use rustical_auth::AuthInfo;
|
use rustical_auth::AuthInfo;
|
||||||
|
use rustical_dav::error::Error;
|
||||||
use rustical_dav::{resource::Resource, xml_snippets::HrefElement};
|
use rustical_dav::{resource::Resource, xml_snippets::HrefElement};
|
||||||
use rustical_store::calendar::CalendarStore;
|
use rustical_store::calendar::CalendarStore;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
@@ -88,7 +89,7 @@ impl<C: CalendarStore + ?Sized> Resource for PrincipalCalendarsResource<C> {
|
|||||||
auth_info: AuthInfo,
|
auth_info: AuthInfo,
|
||||||
_uri_components: Self::UriComponents,
|
_uri_components: Self::UriComponents,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
) -> Result<Self> {
|
) -> Result<Self, Error> {
|
||||||
let cal_store = req
|
let cal_store = req
|
||||||
.app_data::<Data<RwLock<C>>>()
|
.app_data::<Data<RwLock<C>>>()
|
||||||
.ok_or(anyhow!("no calendar store in app_data!"))?
|
.ok_or(anyhow!("no calendar store in app_data!"))?
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use actix_web::HttpRequest;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use rustical_auth::AuthInfo;
|
use rustical_auth::AuthInfo;
|
||||||
|
use rustical_dav::error::Error;
|
||||||
use rustical_dav::{resource::Resource, xml_snippets::HrefElement};
|
use rustical_dav::{resource::Resource, xml_snippets::HrefElement};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use strum::{EnumProperty, EnumString, IntoStaticStr, VariantNames};
|
use strum::{EnumProperty, EnumString, IntoStaticStr, VariantNames};
|
||||||
@@ -52,7 +53,7 @@ impl Resource for RootResource {
|
|||||||
auth_info: AuthInfo,
|
auth_info: AuthInfo,
|
||||||
_uri_components: Self::UriComponents,
|
_uri_components: Self::UriComponents,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
) -> Result<Self> {
|
) -> Result<Self, Error> {
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
prefix,
|
prefix,
|
||||||
principal: auth_info.user_id,
|
principal: auth_info.user_id,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ use actix_web::http::header::ContentType;
|
|||||||
use actix_web::http::StatusCode;
|
use actix_web::http::StatusCode;
|
||||||
use actix_web::web::{Data, Path};
|
use actix_web::web::{Data, Path};
|
||||||
use actix_web::{HttpRequest, HttpResponse};
|
use actix_web::{HttpRequest, HttpResponse};
|
||||||
use anyhow::Result;
|
use anyhow::{anyhow, Result};
|
||||||
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
||||||
use rustical_dav::depth_extractor::Depth;
|
use rustical_dav::depth_extractor::Depth;
|
||||||
use rustical_dav::namespace::Namespace;
|
use rustical_dav::namespace::Namespace;
|
||||||
@@ -74,8 +74,9 @@ pub async fn route_propfind<A: CheckAuthentication, R: Resource, C: CalendarStor
|
|||||||
context: Data<CalDavContext<C>>,
|
context: Data<CalDavContext<C>>,
|
||||||
auth: AuthInfoExtractor<A>,
|
auth: AuthInfoExtractor<A>,
|
||||||
depth: Depth,
|
depth: Depth,
|
||||||
) -> Result<HttpResponse, Error> {
|
) -> Result<HttpResponse, rustical_dav::error::Error> {
|
||||||
let props = parse_propfind(&body)?;
|
// TODO: fix errors
|
||||||
|
let props = parse_propfind(&body).map_err(|_e| anyhow!("propfing parsing error"))?;
|
||||||
let auth_info = auth.inner;
|
let auth_info = auth.inner;
|
||||||
|
|
||||||
let resource = R::acquire_from_request(
|
let resource = R::acquire_from_request(
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ rustical_auth = { path = "../auth/" }
|
|||||||
serde = { version = "1.0.197", features = ["derive"] }
|
serde = { version = "1.0.197", features = ["derive"] }
|
||||||
strum = "0.26"
|
strum = "0.26"
|
||||||
itertools = "0.12"
|
itertools = "0.12"
|
||||||
|
thiserror = "1.0"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use actix_web::{http::StatusCode, HttpResponse};
|
use actix_web::{http::StatusCode, HttpResponse};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::routes::propfind;
|
// use crate::routes::propfind;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
@@ -13,8 +13,8 @@ pub enum Error {
|
|||||||
Unauthorized,
|
Unauthorized,
|
||||||
#[error("Internal server error :(")]
|
#[error("Internal server error :(")]
|
||||||
InternalError,
|
InternalError,
|
||||||
#[error(transparent)]
|
// #[error(transparent)]
|
||||||
PropfindError(#[from] propfind::Error),
|
// PropfindError(#[from] propfind::Error),
|
||||||
#[error("Internal server error")]
|
#[error("Internal server error")]
|
||||||
Other(#[from] anyhow::Error),
|
Other(#[from] anyhow::Error),
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ impl actix_web::error::ResponseError for Error {
|
|||||||
Self::NotFound => StatusCode::NOT_FOUND,
|
Self::NotFound => StatusCode::NOT_FOUND,
|
||||||
Self::BadRequest => StatusCode::BAD_REQUEST,
|
Self::BadRequest => StatusCode::BAD_REQUEST,
|
||||||
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
Self::Unauthorized => StatusCode::UNAUTHORIZED,
|
||||||
Self::PropfindError(e) => e.status_code(),
|
// Self::PropfindError(e) => e.status_code(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
pub mod depth_extractor;
|
pub mod depth_extractor;
|
||||||
|
pub mod error;
|
||||||
pub mod namespace;
|
pub mod namespace;
|
||||||
pub mod resource;
|
pub mod resource;
|
||||||
pub mod xml_snippets;
|
pub mod xml_snippets;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
use crate::{error::Error, xml_snippets::TagList};
|
||||||
use actix_web::{http::StatusCode, HttpRequest};
|
use actix_web::{http::StatusCode, HttpRequest};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
@@ -7,8 +8,6 @@ use serde::Serialize;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use strum::{EnumProperty, VariantNames};
|
use strum::{EnumProperty, VariantNames};
|
||||||
|
|
||||||
use crate::xml_snippets::TagList;
|
|
||||||
|
|
||||||
// A resource is identified by a URI and has properties
|
// A resource is identified by a URI and has properties
|
||||||
// A resource can also be a collection
|
// A resource can also be a collection
|
||||||
// A resource cannot be none, only Methods like PROPFIND, GET, REPORT, etc. can be exposed
|
// A resource cannot be none, only Methods like PROPFIND, GET, REPORT, etc. can be exposed
|
||||||
@@ -25,7 +24,7 @@ pub trait Resource: Sized {
|
|||||||
auth_info: AuthInfo,
|
auth_info: AuthInfo,
|
||||||
uri_components: Self::UriComponents,
|
uri_components: Self::UriComponents,
|
||||||
prefix: String,
|
prefix: String,
|
||||||
) -> Result<Self>;
|
) -> Result<Self, Error>;
|
||||||
|
|
||||||
fn get_path(&self) -> &str;
|
fn get_path(&self) -> &str;
|
||||||
async fn get_members(&self) -> Result<Vec<Self::MemberType>>;
|
async fn get_members(&self) -> Result<Vec<Self::MemberType>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user