From 2773d76e22ea23853485e8e61c69e1c0648414af Mon Sep 17 00:00:00 2001 From: blek Date: Sun, 1 Oct 2023 12:05:08 +1000 Subject: [PATCH] handle stuff using rejection --- filed/src/web/forms.rs | 31 ++++++++++++++++++++++++++--- filed/src/web/mod.rs | 1 + filed/src/web/pages.rs | 7 ++++++- filed/src/web/rejection.rs | 7 +++++++ filed/templates/bad_action_req.html | 1 + 5 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 filed/src/web/rejection.rs create mode 100644 filed/templates/bad_action_req.html diff --git a/filed/src/web/forms.rs b/filed/src/web/forms.rs index 1aafa80..6593938 100644 --- a/filed/src/web/forms.rs +++ b/filed/src/web/forms.rs @@ -5,11 +5,12 @@ use std::collections::HashMap; -use warp::{Filter, reply::Reply, reject::Rejection, filters::multipart::FormData}; +use askama::Template; +use warp::{Filter, reply::{Reply, Html}, reject::Rejection, filters::multipart::FormData, http::StatusCode, Error}; use futures_util::TryStreamExt; use bytes::BufMut; -use super::state::SharedState; +use super::{state::SharedState, pages::BadActionReq, rejection::HttpReject}; pub async fn upload(form: FormData, _state: SharedState) -> Result, Rejection> { @@ -20,7 +21,31 @@ pub async fn upload(form: FormData, _state: SharedState) -> Result Html { let rendered = Index {}; diff --git a/filed/src/web/rejection.rs b/filed/src/web/rejection.rs new file mode 100644 index 0000000..e35816a --- /dev/null +++ b/filed/src/web/rejection.rs @@ -0,0 +1,7 @@ + +#[derive(Debug)] +pub enum HttpReject { + WarpError(warp::Error), + AskamaError(askama::Error) +} +impl warp::reject::Reject for HttpReject {} \ No newline at end of file diff --git a/filed/templates/bad_action_req.html b/filed/templates/bad_action_req.html new file mode 100644 index 0000000..63913c1 --- /dev/null +++ b/filed/templates/bad_action_req.html @@ -0,0 +1 @@ +{% extends "base.html" %} \ No newline at end of file