-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06a4c65
commit 4093c6f
Showing
2 changed files
with
69 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,15 @@ | ||
use flow_websocket_domain::project::ProjectEditingSessionError; | ||
use flow_websocket_infra::persistence::project_repository::ProjectRepositoryError; | ||
use std::fmt; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ProjectServiceError { | ||
#[error(transparent)] | ||
Repository(#[from] ProjectRepositoryError), | ||
|
||
#[error(transparent)] | ||
EditingSession(#[from] ProjectEditingSessionError), | ||
|
||
#[error("Session not setup")] | ||
SessionNotSetup, | ||
|
||
#[error("Snapshot repository error: {0}")] | ||
SnapshotRepository(String), | ||
|
||
#[error("Unexpected error: {0}")] | ||
Unexpected(String), | ||
} | ||
|
||
impl<S, R> From<ProjectEditingSessionError<S, R>> for ProjectServiceError | ||
where | ||
S: fmt::Debug, | ||
R: fmt::Debug, | ||
{ | ||
fn from(err: ProjectEditingSessionError<S, R>) -> Self { | ||
match err { | ||
ProjectEditingSessionError::SessionNotSetup => ProjectServiceError::SessionNotSetup, | ||
ProjectEditingSessionError::Snapshot(repo_err) => { | ||
ProjectServiceError::SnapshotRepository(format!("{:?}", repo_err)) | ||
} | ||
ProjectEditingSessionError::Redis(repo_err) => { | ||
ProjectServiceError::SnapshotRepository(format!("{:?}", repo_err)) | ||
} | ||
ProjectEditingSessionError::Custom(err) => ProjectServiceError::Unexpected(err), | ||
ProjectEditingSessionError::SnapshotNotFound => { | ||
ProjectServiceError::SnapshotRepository("Snapshot not found".to_string()) | ||
} | ||
} | ||
} | ||
} |