Skip to main content

lab_resource_manager/domain/aggregates/identity_link/
errors.rs

1use super::value_objects::ExternalSystem;
2use std::fmt;
3
4/// IdentityLink集約のドメインエラー型
5#[derive(Debug, Clone, PartialEq)]
6pub enum IdentityLinkError {
7    /// 指定された外部システムの識別情報が既に存在する
8    IdentityAlreadyExists {
9        /// 重複している外部システム
10        system: ExternalSystem,
11    },
12    /// 指定された外部システムの識別情報が見つからない
13    IdentityNotFound {
14        /// 見つからなかった外部システム
15        system: ExternalSystem,
16    },
17}
18
19impl fmt::Display for IdentityLinkError {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Self::IdentityAlreadyExists { system } => {
23                write!(
24                    f,
25                    "外部システム {} の識別情報は既に登録されています",
26                    system.as_str()
27                )
28            }
29            Self::IdentityNotFound { system } => {
30                write!(
31                    f,
32                    "外部システム {} の識別情報が見つかりません",
33                    system.as_str()
34                )
35            }
36        }
37    }
38}
39
40impl std::error::Error for IdentityLinkError {}
41
42impl crate::domain::errors::DomainError for IdentityLinkError {}