1use thiserror::Error;
2
3#[cfg(feature = "v4")]
4use world_id_core::AuthenticatorError;
5
6#[derive(Debug, Error, uniffi::Error)]
8pub enum WalletKitError {
9 #[error("invalid_input_{attribute}")]
11 InvalidInput {
12 attribute: String,
14 reason: String,
16 },
17
18 #[error("invalid_number")]
20 InvalidNumber,
21
22 #[error("serialization_error")]
24 SerializationError {
25 error: String,
27 },
28
29 #[error("network_error at {url}: {error}")]
31 NetworkError {
32 url: String,
34 error: String,
36 status: Option<u16>,
38 },
39
40 #[error("request_error")]
42 Reqwest {
43 error: String,
45 },
46
47 #[error("proof_generation_error")]
49 ProofGeneration {
50 error: String,
52 },
53
54 #[error("semaphore_not_enabled")]
56 SemaphoreNotEnabled,
57
58 #[error("credential_not_issued")]
60 CredentialNotIssued,
61
62 #[error("credential_not_mined")]
64 CredentialNotMined,
65
66 #[error("Account is not registered for this authenticator.")]
69 AccountDoesNotExist,
70
71 #[error("Account already exists for this authenticator.")]
73 AccountAlreadyExists,
74
75 #[error("unauthorized_authenticator")]
77 UnauthorizedAuthenticator,
78
79 #[error("unexpected_authenticator_error")]
81 AuthenticatorError {
82 error: String,
84 },
85
86 #[error("unexpected_error: {error}")]
88 Generic {
89 error: String,
91 },
92}
93
94impl From<reqwest::Error> for WalletKitError {
95 fn from(error: reqwest::Error) -> Self {
96 Self::Reqwest {
97 error: error.to_string(),
98 }
99 }
100}
101
102impl From<semaphore_rs::protocol::ProofError> for WalletKitError {
103 fn from(error: semaphore_rs::protocol::ProofError) -> Self {
104 Self::ProofGeneration {
105 error: error.to_string(),
106 }
107 }
108}
109
110#[cfg(feature = "v4")]
111impl From<AuthenticatorError> for WalletKitError {
112 fn from(error: AuthenticatorError) -> Self {
113 match error {
114 AuthenticatorError::AccountDoesNotExist => Self::AccountDoesNotExist,
115 AuthenticatorError::AccountAlreadyExists => Self::AccountAlreadyExists,
116
117 AuthenticatorError::NetworkError(error) => Self::NetworkError {
118 url: error
119 .url()
120 .map(std::string::ToString::to_string)
121 .unwrap_or_default(),
122 error: error.to_string(),
123 status: None,
124 },
125 AuthenticatorError::PublicKeyNotFound => Self::UnauthorizedAuthenticator,
126 AuthenticatorError::GatewayError { status, body } => Self::NetworkError {
127 url: "gateway".to_string(),
128 error: body,
129 status: Some(status.as_u16()),
130 },
131 AuthenticatorError::PrimitiveError(error) => {
132 use world_id_core::primitives::PrimitiveError;
133 match error {
134 PrimitiveError::InvalidInput { attribute, reason } => {
135 Self::InvalidInput { attribute, reason }
136 }
137 _ => Self::Generic {
138 error: error.to_string(),
139 },
140 }
141 }
142
143 _ => Self::AuthenticatorError {
144 error: error.to_string(),
145 },
146 }
147 }
148}