Something went wrong. Try again.
The smokesignal.events web application
Something went wrong. Try again.
2.3 kB · 59 lines
Rust
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960use axum::response::{IntoResponse, Redirect, Response};use http::StatusCode;use thiserror::Error;
use crate::http::utils::stringify;
/// Represents errors that can occur during web session operations.////// These errors are related to the serialization and deserialization of/// web session data used for maintaining user authentication state.#[derive(Debug, Error)]pub(crate) enum WebSessionError { /// Error when web session deserialization fails. /// /// This error occurs when attempting to deserialize a web session from JSON /// format, typically when retrieving a session from storage or a cookie. #[error("error-smokesignal-websession-1 Unable to deserialize WebSession: {0:?}")] DeserializeFailed(serde_json::Error),
/// Error when web session serialization fails. /// /// This error occurs when attempting to serialize a web session to JSON /// format, typically when storing a session in storage or a cookie. #[error("error-smokesignal-websession-2 Unable to serialize WebSession: {0:?}")] SerializeFailed(serde_json::Error),}
#[derive(Debug, Error)]pub(crate) enum MiddlewareAuthError { #[error("error-smokesignal-middleware-auth-1 Access Denied: {0}")] AccessDenied(String),
#[error("error-smokesignal-middleware-auth-2 Not Found")] NotFound,
#[error("error-smokesignal-middleware-auth-3 Unhandled Auth Error: {0:?}")] Anyhow(#[from] anyhow::Error),}
impl IntoResponse for MiddlewareAuthError { fn into_response(self) -> Response { match self { MiddlewareAuthError::AccessDenied(destination) => { let encoded_destination = urlencoding::encode(&destination).to_string(); let args = vec![("destination", encoded_destination.as_str())]; let uri = format!("/oauth/login?{}", stringify(args)); Redirect::to(&uri).into_response() } MiddlewareAuthError::NotFound => { tracing::error!(error = ?self, "access denied"); (StatusCode::NOT_FOUND).into_response() } _ => { tracing::error!(error = ?self, "internal server error"); (StatusCode::INTERNAL_SERVER_ERROR).into_response() } } }}