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.
This commit is contained in:
asepharyana
2026-07-20 06:39:30 +07:00
parent ab1a54b72e
commit e9a8e93c83
39 changed files with 413 additions and 366 deletions
+4 -1
View File
@@ -26,6 +26,7 @@ use zesdex_cms::infrastructure::persistence::{
JsonAppConfigRepository, JsonConversationRepository, JsonSettingsRepository,
MarkdownMemoryRepository,
};
use zesdex_entities::domain::auth::SessionId;
use zesdex_entities::domain::common::store::Store;
use zesdex_iam::domain::repository::SessionRepository;
use zesdex_iam::domain::session::Session;
@@ -127,9 +128,11 @@ impl IamServiceProvider for DefaultIamServiceProvider {
}
fn archive_session(&self, id: &str) -> Result<()> {
let sid = SessionId::new(id)
.map_err(|e| anyhow::anyhow!("invalid session id: {e}"))?;
let mut session = self
.session_repo
.load_session(&self.base_dir, id)
.load_session(&self.base_dir, &sid)
.with_context(|| format!("session not found: {id}"))?;
session.archived = true;
session.updated_at = std::time::SystemTime::now()