diff options
| author | Emīls Piņķis <emils@mullvad.net> | 2019-10-08 12:36:23 +0100 |
|---|---|---|
| committer | Emīls Piņķis <emils@mullvad.net> | 2019-10-08 14:56:26 +0100 |
| commit | 305b8c005cd7c38dae6d1365a2b426de17584e8f (patch) | |
| tree | f4f36c7697feba57b5ce45247a0cd076ac3370e6 | |
| parent | 07a7ed107909dfbea77029c732c8c4c47dc424a0 (diff) | |
| download | mullvadvpn-305b8c005cd7c38dae6d1365a2b426de17584e8f.tar.xz mullvadvpn-305b8c005cd7c38dae6d1365a2b426de17584e8f.zip | |
Add voucher submission types
| -rw-r--r-- | mullvad-types/src/account.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/mullvad-types/src/account.rs b/mullvad-types/src/account.rs index c8de40ac54..909b6c0070 100644 --- a/mullvad-types/src/account.rs +++ b/mullvad-types/src/account.rs @@ -7,3 +7,41 @@ pub type AccountToken = String; pub struct AccountData { pub expiry: DateTime<Utc>, } + +/// Data-structure that's returned from successfuly invocation of the mullvad API's +/// `submit_voucher(account, voucher)` RPC +#[derive(serde::Deserialize, serde::Serialize, Debug)] +pub struct VoucherSubmission { + /// Amount of time added to the account + pub time_added: u64, + /// Updated expiry time + pub new_expiry: DateTime<Utc>, +} + +/// Mapping of mullvad-api errors +#[derive(err_derive::Error, Debug)] +pub enum VoucherError { + /// Error code -400 + #[error(display = "Bad voucher code")] + BadVoucher, + /// Error code -401 + #[error(display = "Voucher already used")] + VoucherAlreadyUsed, + /// Error code -100 + #[error(display = "Server internal error")] + InternalError, + #[error(display = "Unknown error, _0")] + UnknownError(i64), +} + +impl VoucherError { + /// Create error from RPC error code. + pub fn from_rpc_error_code(err_code: i64) -> VoucherError { + match err_code { + -400 => VoucherError::BadVoucher, + -401 => VoucherError::VoucherAlreadyUsed, + -100 => VoucherError::InternalError, + err => VoucherError::UnknownError(err), + } + } +} |
