1use http::StatusCode;
2
3use crate::database::redb::RedbError;
4use crate::event_message::cesr_adapter::ParseError;
5use crate::keys::KeysError;
6#[cfg(feature = "oobi")]
7use crate::oobi::{error::OobiError, Role};
8#[cfg(feature = "oobi-manager")]
9use crate::transport::TransportError;
10use crate::{actor::SignedQueryError, error::Error as KeriError, prefix::IdentifierPrefix};
11use said::version::error::Error as VersionError;
12
13#[derive(Debug, thiserror::Error, serde::Serialize, serde::Deserialize)]
14pub enum ActorError {
15 #[cfg(feature = "oobi-manager")]
16 #[error("network request failed")]
17 TransportError(Box<TransportError>),
18
19 #[error("keri error")]
20 KeriError(#[from] KeriError),
21
22 #[error("DB error: {0}")]
23 DbError(String),
24
25 #[cfg(feature = "oobi")]
26 #[error("OOBI error")]
27 OobiError(#[from] OobiError),
28
29 #[error("processing query failed")]
30 QueryError(#[from] SignedQueryError),
31
32 #[error("Keri event parsing error: {0}")]
33 ParseError(#[from] ParseError),
34
35 #[error("location not found for {id:?}")]
36 NoLocation { id: IdentifierPrefix }, #[error("wrong reply route")]
39 WrongReplyRoute,
40
41 #[cfg(feature = "oobi")]
42 #[error("role {role:?} missing for {id:?}")]
43 MissingRole { role: Role, id: IdentifierPrefix }, #[error("no identifier state for prefix {prefix:?}")]
46 NoIdentState { prefix: IdentifierPrefix },
47
48 #[error("Missing signer identifier")]
49 MissingSignerId,
50
51 #[error("Signing error: {0}")]
52 SigningError(#[from] KeysError),
53
54 #[error("Error: {0}")]
55 GeneralError(String),
56
57 #[error("KEL not found")]
58 NotFound(IdentifierPrefix),
59
60 #[error("Unexpected response: {0}")]
61 UnexpectedResponse(String),
62}
63
64#[cfg(feature = "oobi-manager")]
65impl From<TransportError> for ActorError {
66 fn from(err: TransportError) -> Self {
67 ActorError::TransportError(Box::new(err))
68 }
69}
70
71impl From<VersionError> for ActorError {
72 fn from(err: VersionError) -> Self {
73 ActorError::KeriError(err.into())
74 }
75}
76
77impl From<RedbError> for ActorError {
78 fn from(err: RedbError) -> Self {
79 ActorError::DbError(err.to_string())
80 }
81}
82
83impl ActorError {
84 pub fn http_status_code(&self) -> StatusCode {
85 match self {
86 ActorError::DbError(_) => StatusCode::INTERNAL_SERVER_ERROR,
87
88 ActorError::KeriError(err) => match err {
89 KeriError::DeserializeError(_) | KeriError::IncorrectDigest => {
90 StatusCode::BAD_REQUEST
91 }
92
93 KeriError::FaultySignatureVerification | KeriError::SignatureVerificationError => {
94 StatusCode::FORBIDDEN
95 }
96
97 _ => StatusCode::INTERNAL_SERVER_ERROR,
98 },
99
100 #[cfg(feature = "oobi")]
101 ActorError::OobiError(OobiError::SignerMismatch) => StatusCode::UNAUTHORIZED,
102
103 _ => StatusCode::INTERNAL_SERVER_ERROR,
104 }
105 }
106}