//! # 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- :
` 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- :
` #[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() } } } }