diff options
| author | gennyble <gen@nyble.dev> | 2026-09-25 03:56:11 -0500 |
|---|---|---|
| committer | gennyble <gen@nyble.dev> | 2026-09-25 03:56:11 -0500 |
| commit | ba592de54cd3dce52eb2096dabbe748107f5db2b (patch) | |
| tree | 4a23377e9788630e09c669e9ed18aecd27673ee7 /splorm/src/runtime_error.rs | |
| parent | f4d8e8d03c1b80d5c59ee85631d5a78048892a32 (diff) | |
splorm auth
Diffstat (limited to 'splorm/src/runtime_error.rs')
| -rw-r--r-- | splorm/src/runtime_error.rs | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/splorm/src/runtime_error.rs b/splorm/src/runtime_error.rs index 225c2d4..bdcb472 100644 --- a/splorm/src/runtime_error.rs +++ b/splorm/src/runtime_error.rs @@ -6,6 +6,9 @@ use axum::{ }; use camino::Utf8PathBuf; use gny::sternum::Sternum; +use somethings::DatabaseError; + +use crate::QueryParseError; #[derive(Copy, Clone, Debug, PartialEq, Sternum)] pub enum InvalidPathReason { @@ -43,6 +46,19 @@ pub enum RuntimeError { source: Option<bempline::ParseError>, system_path: Utf8PathBuf, }, + QueryParseError { + source: QueryParseError, + }, + IncompleteForm { + missing_field: &'static str, + }, + DatabaseError { + source: DatabaseError, + }, + AuthenticationFailed { + name: String, + }, + InvalidSession, Generic404, Unknown, } @@ -94,6 +110,16 @@ impl RuntimeError { } } + pub fn incomplete_form(field: &'static str) -> Self { + Self::IncompleteForm { + missing_field: field, + } + } + + pub fn authentication_failed(name: String) -> Self { + Self::AuthenticationFailed { name } + } + pub fn generic_404() -> Self { RuntimeError::Generic404 } @@ -111,6 +137,11 @@ impl RuntimeError { FileErrorReason::Unknown => 500, }, Self::TemplateError { .. } => 500, + Self::QueryParseError { .. } => 400, + Self::IncompleteForm { .. } => 400, + Self::DatabaseError { .. } => 500, + Self::AuthenticationFailed { .. } => 403, + Self::InvalidSession => 403, Self::Generic404 => 404, Self::Unknown => 500, } @@ -143,6 +174,21 @@ impl fmt::Display for RuntimeError { Some(pe) => write!(f, "template error: {pe}. system={system_path}"), None => write!(f, "template error. reason={reason}, system={system_path}"), }, + RuntimeError::QueryParseError { source } => { + write!(f, "failed to parse query. {source}") + } + RuntimeError::IncompleteForm { missing_field } => { + write!(f, "missing field {missing_field} in form") + } + RuntimeError::DatabaseError { source } => { + write!(f, "database error: {source}") + } + RuntimeError::AuthenticationFailed { name } => { + write!(f, "authentication failed for '{name}'") + } + RuntimeError::InvalidSession => { + write!(f, "the session id was invalid") + } RuntimeError::Generic404 => write!(f, "generic 404"), RuntimeError::Unknown => write!(f, "unknown error!"), } @@ -153,6 +199,15 @@ struct PresentableRuntimeError<'re>(&'re RuntimeError); impl<'re> fmt::Display for PresentableRuntimeError<'re> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { macro_rules! estr { + (400) => { + write!(f, "bad request") + }; + (400 incomplete $missing:ident) => { + write!(f, "incomplete form. field {} is required", $missing) + }; + (403) => { + write!(f, "authenticated failed") + }; (404) => { write!(f, "the requested file could not be found") }; @@ -173,6 +228,11 @@ impl<'re> fmt::Display for PresentableRuntimeError<'re> { FileErrorReason::Unknown => estr!(500), }, RuntimeError::TemplateError { .. } => estr!(500), + RuntimeError::QueryParseError { .. } => estr!(400), + RuntimeError::IncompleteForm { missing_field } => estr!(400 incomplete missing_field), + RuntimeError::DatabaseError { .. } => estr!(500), + RuntimeError::AuthenticationFailed { .. } => estr!(403), + RuntimeError::InvalidSession => estr!(403), RuntimeError::Generic404 => estr!(404), RuntimeError::Unknown => estr!(500), } @@ -208,3 +268,15 @@ fn make_basic_error<S: std::fmt::Display>(status: u16, msg: S) -> Response { .unwrap() .into_response() } + +impl From<QueryParseError> for RuntimeError { + fn from(qpe: QueryParseError) -> Self { + RuntimeError::QueryParseError { source: qpe } + } +} + +impl From<DatabaseError> for RuntimeError { + fn from(dbe: DatabaseError) -> Self { + RuntimeError::DatabaseError { source: dbe } + } +} |
