volt_client_grpc/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, VoltError>;
7
8#[derive(Error, Debug)]
10pub enum VoltError {
11 #[error("Configuration error: {0}")]
13 ConfigError(String),
14
15 #[error("Missing required configuration: {0}")]
17 MissingConfig(String),
18
19 #[error("Authentication failed: {0}")]
21 AuthenticationFailed(String),
22
23 #[error("Connection error: {0}")]
25 ConnectionError(String),
26
27 #[error("gRPC error: {0}")]
29 GrpcError(#[from] tonic::Status),
30
31 #[error("Transport error: {0}")]
33 TransportError(#[from] tonic::transport::Error),
34
35 #[error("IO error: {0}")]
37 IoError(#[from] std::io::Error),
38
39 #[error("JSON error: {0}")]
41 JsonError(#[from] serde_json::Error),
42
43 #[error("Crypto error: {0}")]
45 CryptoError(String),
46
47 #[error("Key error: {0}")]
49 KeyError(String),
50
51 #[error("Certificate error: {0}")]
53 CertificateError(String),
54
55 #[error("JWT error: {0}")]
57 JwtError(#[from] jsonwebtoken::errors::Error),
58
59 #[error("Session error: {0}")]
61 SessionError(String),
62
63 #[error("Method not found: {0}")]
65 MethodNotFound(String),
66
67 #[error("Invalid response: {0}")]
69 InvalidResponse(String),
70
71 #[error("Timeout: {0}")]
73 Timeout(String),
74
75 #[error("Request denied: {0}")]
77 Denied(String),
78
79 #[error("Protocol error: {0}")]
81 ProtocolError(String),
82
83 #[error("DID resolution error: {0}")]
85 DidResolutionError(String),
86
87 #[error("HTTP error: {0}")]
89 HttpError(#[from] reqwest::Error),
90
91 #[error("Server error: {0}")]
93 ServerError(String),
94
95 #[error("Permission denied: {0}")]
97 PermissionDenied(String),
98
99 #[error("CRDT error: {0}")]
101 CrdtError(String),
102
103 #[error("Invalid argument: {0}")]
105 InvalidArgument(String),
106
107 #[error("Client not initialized")]
109 NotInitialized,
110
111 #[error("Client not connected")]
113 NotConnected,
114
115 #[error("Client already connected")]
117 AlreadyConnected,
118
119 #[error("Signature verification failed")]
121 SignatureVerificationFailed,
122
123 #[error("Encryption error: {0}")]
125 EncryptionError(String),
126
127 #[error("Decryption error: {0}")]
129 DecryptionError(String),
130
131 #[error("Base64 decode error: {0}")]
133 Base64Error(#[from] base64::DecodeError),
134
135 #[error("Internal error: {0}")]
137 Internal(String),
138}
139
140impl VoltError {
141 pub fn config<S: Into<String>>(msg: S) -> Self {
143 VoltError::ConfigError(msg.into())
144 }
145
146 pub fn missing_config<S: Into<String>>(field: S) -> Self {
148 VoltError::MissingConfig(field.into())
149 }
150
151 pub fn auth<S: Into<String>>(msg: S) -> Self {
153 VoltError::AuthenticationFailed(msg.into())
154 }
155
156 pub fn connection<S: Into<String>>(msg: S) -> Self {
158 VoltError::ConnectionError(msg.into())
159 }
160
161 pub fn crypto<S: Into<String>>(msg: S) -> Self {
163 VoltError::CryptoError(msg.into())
164 }
165
166 pub fn key<S: Into<String>>(msg: S) -> Self {
168 VoltError::KeyError(msg.into())
169 }
170
171 pub fn session<S: Into<String>>(msg: S) -> Self {
173 VoltError::SessionError(msg.into())
174 }
175
176 pub fn internal<S: Into<String>>(msg: S) -> Self {
178 VoltError::Internal(msg.into())
179 }
180
181 pub fn serialization<S: Into<String>>(msg: S) -> Self {
183 VoltError::InvalidResponse(msg.into())
184 }
185
186 pub fn protocol<S: Into<String>>(msg: S) -> Self {
188 VoltError::ProtocolError(msg.into())
189 }
190
191 pub fn server(code: i32, msg: &str) -> Self {
193 VoltError::ServerError(format!("Code {}: {}", code, msg))
194 }
195
196 pub fn grpc(code: tonic::Code, msg: &str) -> Self {
198 VoltError::GrpcError(tonic::Status::new(code, msg.to_string()))
199 }
200}