diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 49 |
1 files changed, 2 insertions, 47 deletions
diff --git a/src/main.rs b/src/main.rs index 658a245..99956c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,9 +19,7 @@ use pulldown_cmark::Options; use pulldown_cmark::Parser; use serde::Deserialize; use sputnik::html_escape; -use sputnik::hyper_body::FormError; use sputnik::mime; -use sputnik::request::QueryError; use sputnik::request::SputnikParts; use sputnik::response::SputnikBuilder; use std::convert::Infallible; @@ -29,7 +27,6 @@ use std::env; use std::path::Component; use std::path::Path; use std::path::PathBuf; -use std::str::Utf8Error; use std::sync::Arc; use url::Url; @@ -41,9 +38,11 @@ use { use crate::controller::MultiUserController; use crate::controller::SoloController; +use crate::error::Error; mod controller; mod diff; +mod error; mod forms; mod get_routes; mod post_routes; @@ -191,31 +190,6 @@ async fn serve<C: Controller + Send + Sync + 'static>(controller: C, args: Args) server.await.expect("server error"); } -pub enum Error { - /// A 400 bad request error. - BadRequest(String), - /// A 401 unauthorized error. - Unauthorized(String, Context), - /// A 403 forbidden error. - Forbidden(String), - /// A 404 not found error. - NotFound(String), - /// A 500 internal server error. - Internal(String), - /// A 302 redirect to the given path. - Redirect(String), - - // TODO: use Redirect instead - /// Missing trailing slash. - MissingTrailingSlash(String), -} - -impl From<Utf8Error> for Error { - fn from(_: Utf8Error) -> Self { - Self::BadRequest("invalid UTF-8".into()) - } -} - async fn service<C: Controller>( controller: Arc<C>, args: Arc<Args>, @@ -326,13 +300,6 @@ fn default_action() -> String { "view".into() } -impl From<git2::Error> for Error { - fn from(e: git2::Error) -> Self { - eprintln!("git error: {}", e); - Self::Internal("something went wrong with git".into()) - } -} - #[derive(Eq, PartialEq, Hash, Clone)] pub struct Branch(String); @@ -491,18 +458,6 @@ fn action_links<C: Controller>(active_action: &str, controller: &C, ctx: &Contex out } -impl From<FormError> for Error { - fn from(e: FormError) -> Self { - Self::BadRequest(e.to_string()) - } -} - -impl From<QueryError> for Error { - fn from(e: QueryError) -> Self { - Self::BadRequest(e.to_string()) - } -} - pub struct Context { repo: Repository, parts: Parts, |