1pub use bitwarden_api_base::Error as ApiError;
4#[cfg(feature = "internal")]
5use bitwarden_error::bitwarden_error;
6use thiserror::Error;
7
8#[derive(Debug, Error)]
10#[error("The client is not authenticated or the session has expired")]
11pub struct NotAuthenticatedError;
12
13#[derive(Debug, Error, serde::Serialize, serde::Deserialize, Clone)]
15#[error("The client user ID is already set")]
16pub struct UserIdAlreadySetError;
17
18#[derive(Debug, Error)]
20#[error("The response received was missing a required field: {0}")]
21pub struct MissingFieldError(pub &'static str);
22
23#[derive(Debug, thiserror::Error)]
25#[error("Wrong password")]
26pub struct WrongPasswordError;
27
28#[derive(Debug, thiserror::Error)]
30#[error("Missing private key")]
31pub struct MissingPrivateKeyError;
32
33#[cfg(feature = "internal")]
36#[bitwarden_error(flat)]
37#[derive(Debug, thiserror::Error)]
38pub enum StatefulCryptoError {
39 #[error("Security state is required, but missing")]
42 MissingSecurityState,
43 #[error("Expected user in account cryptography version {expected}, but got {got}")]
45 WrongAccountCryptoVersion {
46 expected: String,
48 got: u32,
50 },
51 #[error("Crypto error, {0}")]
52 Crypto(#[from] bitwarden_crypto::CryptoError),
53}
54
55#[macro_export]
60macro_rules! require {
61 ($val:expr) => {
62 match $val {
63 Some(val) => val,
64 None => return Err($crate::MissingFieldError(stringify!($val)).into()),
65 }
66 };
67}