miden_client/rpc/errors/node/
account.rs1use alloc::string::String;
2
3use thiserror::Error;
4
5use crate::rpc::errors::GrpcError;
6
7#[derive(Debug, Clone, PartialEq, Eq, Error)]
12pub enum GetAccountError {
13 #[error("internal server error")]
15 Internal,
16 #[error("deserialization failed")]
18 DeserializationFailed,
19 #[error("account not found")]
21 AccountNotFound,
22 #[error("account is not public")]
24 AccountNotPublic,
25 #[error("unknown block")]
27 UnknownBlock,
28 #[error("block pruned")]
30 BlockPruned,
31 #[error("unknown error code {code}: {message}")]
34 Unknown { code: u8, message: String },
35}
36
37impl GetAccountError {
38 pub fn from_code(code: u8, message: &str) -> Self {
39 match code {
40 0 => Self::Internal,
41 1 => Self::DeserializationFailed,
42 2 => Self::AccountNotFound,
43 3 => Self::AccountNotPublic,
44 4 => Self::UnknownBlock,
45 5 => Self::BlockPruned,
46 _ => Self::Unknown { code, message: String::from(message) },
47 }
48 }
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, Error)]
56pub enum RegisterAccountError {
57 #[error("invitation code does not exist")]
58 InvitationNotFound,
59 #[error("the invitation code or the account is already registered")]
60 AlreadyRegistered,
61 #[error("invalid registration request: {0}")]
64 InvalidRequest(String),
65}
66
67impl RegisterAccountError {
68 pub fn from_grpc_error(error_kind: &GrpcError, message: &str) -> Option<Self> {
73 match error_kind {
74 GrpcError::NotFound => Some(Self::InvitationNotFound),
75 GrpcError::AlreadyExists => Some(Self::AlreadyRegistered),
76 GrpcError::InvalidArgument => Some(Self::InvalidRequest(String::from(message))),
77 _ => None,
78 }
79 }
80}