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