π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
rust/cli: refresh error model
Prateek Sunala848b2c7c3c0
diff --git a/rust/cli/src/models/error.rs b/rust/cli/src/models/error.rsindex 4193370036..8962202e32 100644--- a/rust/cli/src/models/error.rs+++ b/rust/cli/src/models/error.rs@@ -1,3 +1,4 @@+use ente_core::crypto::CryptoError;use thiserror::Error;#[derive(Error, Debug)]@@ -40,6 +41,84 @@ pub enum Error {#[error("{0}")]Generic(String),++ #[error("Too many requests. Please wait a minute and try again.")]+ RateLimited,++ #[error("API error ({status}): {message}")]+ ApiError { status: u16, message: String },+}++impl Error {+ /// Create an API error with status code+ pub fn api_error(status: u16, message: String) -> Self {+ Error::ApiError { status, message }+ }++ /// Check if this is a specific HTTP status code+ pub fn is_status(&self, code: u16) -> bool {+ matches!(self, Error::ApiError { status, .. } if *status == code)+ }++ /// Check if this is an authentication error (401)+ pub fn is_unauthorized(&self) -> bool {+ self.is_status(401)+ }++ /// Check if this is a session expired error (410)+ pub fn is_gone(&self) -> bool {+ self.is_status(410)+ }++ /// Check if this is a rate limit error (429)+ pub fn is_rate_limited(&self) -> bool {+ matches!(self, Error::RateLimited) || self.is_status(429)+ }++ /// Check if this is a "not yet complete" error (400/404 for passkey polling)+ pub fn is_not_ready(&self) -> bool {+ self.is_status(400) || self.is_status(404)+ }++ /// Check if retry is appropriate for this error+ pub fn is_retryable_auth(&self) -> bool {+ self.is_unauthorized() || self.is_status(400)+ }++ /// Get a user-friendly display message+ pub fn user_message(&self) -> String {+ match self {+ Error::RateLimited => {+ "β³ Too many requests. Please wait a minute and try again.".to_string()+ }+ Error::ApiError { status: 401, .. } => {+ "π Invalid credentials. Please check your password.".to_string()+ }+ Error::ApiError { status: 410, .. } => {+ "π Session expired. Please restart the login process.".to_string()+ }+ Error::ApiError { status: 429, .. } => {+ "β³ Too many requests. Please wait a minute and try again.".to_string()+ }+ Error::ApiError { status: 404, .. } => "π Not found.".to_string(),+ Error::AuthenticationFailed(msg) => format!("π {}", msg),+ Error::Crypto(_) => "π Decryption failed. Please check your password.".to_string(),+ Error::NotFound(msg) => format!("π {}", msg),+ Error::Network(_) => "π Network error. Please check your connection.".to_string(),+ Error::InvalidInput(msg) => format!("β οΈ {}", msg),+ _ => format!("β {}", self),+ }+ }+}++impl From<CryptoError> for Error {+ fn from(err: CryptoError) -> Self {+ match err {+ CryptoError::Base64Decode(source) => Error::Base64Decode(source),+ CryptoError::Io(source) => Error::Io(source),+ other => Error::Crypto(other.to_string()),+ }+ }}pub type Result<T> = std::result::Result<T, Error>;