Files
zesdex/crates/zesdex-cms/src/domain/error.rs
T
asepharyana e9a8e93c83 Refactor session ID handling and improve error management
- Introduced `SessionId` newtype for validated session identifiers, ensuring safety against path traversal attacks.
- Updated session repository methods to accept `SessionId` instead of raw strings, enhancing type safety.
- Removed redundant error handling in repository methods by leveraging the new `Error` type from `zesdex_utils`.
- Simplified atomic JSON write operations by eliminating unnecessary error conversions.
- Enhanced integer casting with a new `CastOr` trait for safer narrowing conversions.
- Removed deprecated error handling code and consolidated error types across the codebase.
- Updated HTTP handlers to utilize the new session ID validation, improving overall robustness.
2026-07-20 06:39:30 +07:00

42 lines
1.6 KiB
Rust

//! Domain error types for the CMS crate.
//!
//! Typed error enums for repository and service operations.
//! The `RepositoryError` type is re-exported from `zesdex_utils::Error`,
//! which has all needed variants: `NotFound`, `Conflict`, `Io`, `Serde`,
//! `InvalidId`, `Other`, etc.
//!
//! `From` impls are generated by `thiserror::Error` derive macros.
//! Anyhow's blanket `From<E: StdError + Send + Sync + 'static>`
//! covers conversion to `anyhow::Error` for downstream code.
// ---------------------------------------------------------------------------
// RepositoryError (type alias)
// ---------------------------------------------------------------------------
/// Re-export shared repository error from `zesdex_utils`.
pub use zesdex_utils::Error as RepositoryError;
// `From<RepositoryError> for anyhow::Error` is covered by anyhow's blanket
// `impl<E: StdError + Send + Sync + 'static> From<E> for Error` — no
// explicit impl needed.
// ---------------------------------------------------------------------------
// ServiceError
// ---------------------------------------------------------------------------
/// Errors from service / use-case operations in the CMS domain.
#[derive(Debug, thiserror::Error)]
pub enum ServiceError {
/// A repository operation failed.
#[error("repository error: {0}")]
Repository(#[from] RepositoryError),
/// The provided input is invalid.
#[error("invalid input: {0}")]
InvalidInput(String),
/// A generic error with a message.
#[error("{0}")]
Other(String),
}
// `From<ServiceError> for anyhow::Error` is covered by anyhow's blanket impl.