cloud.rs 1.5 KB

1234567891011121314151617181920212223242526272829
  1. use client_api::error::AppError;
  2. use crate::{ErrorCode, FlowyError};
  3. impl From<AppError> for FlowyError {
  4. fn from(error: AppError) -> Self {
  5. let code = match error.code {
  6. client_api::error::ErrorCode::Ok => ErrorCode::Internal,
  7. client_api::error::ErrorCode::Unhandled => ErrorCode::Internal,
  8. client_api::error::ErrorCode::RecordNotFound => ErrorCode::RecordNotFound,
  9. client_api::error::ErrorCode::RecordAlreadyExists => ErrorCode::RecordAlreadyExists,
  10. client_api::error::ErrorCode::InvalidEmail => ErrorCode::EmailFormatInvalid,
  11. client_api::error::ErrorCode::InvalidPassword => ErrorCode::PasswordFormatInvalid,
  12. client_api::error::ErrorCode::OAuthError => ErrorCode::UserUnauthorized,
  13. client_api::error::ErrorCode::MissingPayload => ErrorCode::MissingPayload,
  14. client_api::error::ErrorCode::OpenError => ErrorCode::Internal,
  15. client_api::error::ErrorCode::InvalidUrl => ErrorCode::InvalidURL,
  16. client_api::error::ErrorCode::InvalidRequestParams => ErrorCode::InvalidParams,
  17. client_api::error::ErrorCode::UrlMissingParameter => ErrorCode::InvalidParams,
  18. client_api::error::ErrorCode::InvalidOAuthProvider => ErrorCode::InvalidAuthConfig,
  19. client_api::error::ErrorCode::NotLoggedIn => ErrorCode::UserUnauthorized,
  20. client_api::error::ErrorCode::NotEnoughPermissions => ErrorCode::NotEnoughPermissions,
  21. client_api::error::ErrorCode::UserNameIsEmpty => ErrorCode::UserNameIsEmpty,
  22. _ => ErrorCode::Internal,
  23. };
  24. FlowyError::new(code, error.message)
  25. }
  26. }