Something went wrong. Try again.
The smokesignal.events web application
Something went wrong. Try again.
7.3 kB · 187 lines
Rust
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188//! # Web Error Types//!//! This module defines the top-level error type for the HTTP layer that aggregates//! all domain-specific errors in the application. This allows errors to be handled//! uniformly at the HTTP boundary and converted into appropriate HTTP responses.//!//! Specific error variants use their own error codes, while general errors use the//! format: `error-smokesignal-web-<number> <message>: <details>`
use axum::http::StatusCode;use axum::response::IntoResponse;use axum::response::Response;use thiserror::Error;
use super::acceptance_error::AcceptanceError;use super::blob_error::BlobError;use super::common_error::CommonError;use super::event_view_errors::EventViewError;use super::import_error::ImportError;use super::lfg_error::LfgError;use super::login_error::LoginError;use super::middleware_errors::MiddlewareAuthError;use super::share_bluesky_error::ShareBlueskyError;use super::url_error::UrlError;
/// Represents all possible errors that can occur in the HTTP layer.////// This enum serves as an aggregation point for all domain-specific errors/// in the application, allowing them to be handled uniformly at the HTTP boundary.////// Most variants use transparent error forwarding to preserve the original error message/// and error code, while a few web-specific errors have their own error code format:/// `error-smokesignal-web-<number> <message>: <details>`#[derive(Debug, Error)]pub(crate) enum WebError { /// Error when authentication middleware fails. /// /// This error occurs when there are issues with verifying a user's identity /// through the authentication middleware, such as invalid credentials or /// expired sessions. /// /// **Error Code:** `error-smokesignal-web-1` #[error("error-smokesignal-web-1 Middleware Auth Error: {0:?}")] MiddlewareAuthError(#[from] MiddlewareAuthError),
/// Error when an unexpected error occurs that isn't covered by other error types. /// /// This error is a fallback for any unhandled errors in the system. In production, /// these should be rare as most errors should be properly typed. /// /// **Error Code:** `error-smokesignal-web-2` /// /// Note: This should be replaced with more specific error types as part of /// the ongoing effort to use typed errors throughout the codebase. #[error("error-smokesignal-web-2 Unhandled web error: {0:?}")] Anyhow(#[from] anyhow::Error),
/// Common HTTP errors. /// /// This variant wraps errors from the common error module, which contains /// frequently used error types shared across HTTP handlers. #[error(transparent)] Common(#[from] CommonError),
/// Login-related errors. /// /// This error occurs during login operations, such as invalid credentials, /// account lockouts, or missing account information. #[error(transparent)] Login(#[from] LoginError),
/// Cache operation errors. /// /// This error occurs when there are issues with cache operations such as /// connection failures or data invalidation problems. #[error(transparent)] Cache(#[from] crate::storage::errors::CacheError),
/// Configuration errors. /// /// This error occurs when there are issues with application configuration, /// such as missing environment variables or invalid settings. #[error(transparent)] ConfigError(#[from] crate::config_errors::ConfigError),
/// Database storage errors. /// /// This error occurs when there are issues with database operations, /// such as query failures or transaction issues. #[error(transparent)] StorageError(#[from] crate::storage::errors::StorageError),
/// Event view errors. /// /// This error occurs when there are issues with retrieving or /// displaying events, such as invalid parameters or missing data. #[error(transparent)] EventViewError(#[from] EventViewError),
/// Event viewing errors. /// /// This error occurs when there are issues with viewing specific events, /// such as permission problems or invalid event identifiers. #[error(transparent)] ViewEventError(#[from] super::view_event_error::ViewEventError),
/// Token refresh errors. /// /// This error occurs when there are issues with refreshing authentication /// tokens, such as expired refresh tokens or validation failures. #[error(transparent)] RefreshError(#[from] crate::refresh_tokens_errors::RefreshError),
/// URL processing errors. /// /// This error occurs when there are issues with URL processing or validation, /// such as malformed URLs or invalid parameters. #[error(transparent)] UrlError(#[from] UrlError),
/// Import-related errors. /// /// This error occurs when there are issues with importing data into the system, /// such as format incompatibilities or validation failures. #[error(transparent)] ImportError(#[from] ImportError),
/// Email-related errors. /// /// This error occurs when there are issues with email operations, /// such as template rendering, email sending, or token generation. #[error(transparent)] EmailError(#[from] crate::email_errors::EmailError),
/// Image processing errors. /// /// This error occurs when there are issues with image operations, /// such as validation, resizing, or format conversion. #[error(transparent)] ImageError(#[from] crate::image_errors::ImageError),
/// RSVP acceptance errors. /// /// This error occurs when there are issues with the RSVP acceptance workflow, /// such as ticket creation, validation, or record management. #[error(transparent)] AcceptanceError(#[from] AcceptanceError),
/// Blob and profile handling errors. /// /// This error occurs when there are issues with blob uploads or profile management, /// such as avatar/banner uploads or AT Protocol record operations. #[error(transparent)] BlobError(#[from] BlobError),
/// Looking For Group (LFG) errors. /// /// This error occurs when there are issues with LFG operations, /// such as creating, viewing, or deactivating LFG records. #[error(transparent)] LfgError(#[from] LfgError),
/// Share to Bluesky errors. /// /// This error occurs when there are issues with sharing RSVP to Bluesky, /// such as post creation failures or event not found. #[error(transparent)] ShareBlueskyError(#[from] ShareBlueskyError),}
/// Implementation of Axum's `IntoResponse` trait for WebError.////// This implementation converts errors into appropriate HTTP responses:/// - Authentication errors use their specialized response handling/// - All other errors are converted to a generic 500 Internal Server Error/// and logged with the `tracing` system.impl IntoResponse for WebError { fn into_response(self) -> Response { match self { WebError::MiddlewareAuthError(err) => err.into_response(), _ => { tracing::error!(error = ?self, "internal server error"); StatusCode::INTERNAL_SERVER_ERROR.into_response() } } }}