fix: af cloud sync auth (#3873)

* feat: open workspace

* chore: update env docs

* fix: invalid user callback

* fix: token invalid

* chore: update

* chore: update

* chore: update

* chore: fix test

* chore: fix tauri build
This commit is contained in:
Nathan.fooo
2023-11-05 14:00:24 +08:00
committed by GitHub
parent b35d6131d4
commit 1025b6d553
59 changed files with 658 additions and 478 deletions

View File

@ -98,9 +98,6 @@ pub enum ErrorCode {
#[error("user id is empty or whitespace")]
UserIdInvalid = 30,
#[error("User not exist")]
UserNotExist = 31,
#[error("Text is too long")]
TextTooLong = 32,

View File

@ -55,6 +55,10 @@ impl FlowyError {
self.code == ErrorCode::RecordNotFound
}
pub fn is_unauthorized(&self) -> bool {
self.code == ErrorCode::UserUnauthorized || self.code == ErrorCode::RecordNotFound
}
static_flowy_error!(internal, ErrorCode::Internal);
static_flowy_error!(record_not_found, ErrorCode::RecordNotFound);
static_flowy_error!(workspace_name, ErrorCode::WorkspaceNameInvalid);
@ -87,7 +91,6 @@ impl FlowyError {
);
static_flowy_error!(name_empty, ErrorCode::UserNameIsEmpty);
static_flowy_error!(user_id, ErrorCode::UserIdInvalid);
static_flowy_error!(user_not_exist, ErrorCode::UserNotExist);
static_flowy_error!(text_too_long, ErrorCode::TextTooLong);
static_flowy_error!(invalid_data, ErrorCode::InvalidParams);
static_flowy_error!(out_of_bounds, ErrorCode::OutOfBounds);

View File

@ -1,26 +1,25 @@
use client_api::error::AppError;
use client_api::error::{AppResponseError, ErrorCode as AppErrorCode};
use crate::{ErrorCode, FlowyError};
impl From<AppError> for FlowyError {
fn from(error: AppError) -> Self {
impl From<AppResponseError> for FlowyError {
fn from(error: AppResponseError) -> Self {
let code = match error.code {
client_api::error::ErrorCode::Ok => ErrorCode::Internal,
client_api::error::ErrorCode::Unhandled => ErrorCode::Internal,
client_api::error::ErrorCode::RecordNotFound => ErrorCode::RecordNotFound,
client_api::error::ErrorCode::RecordAlreadyExists => ErrorCode::RecordAlreadyExists,
client_api::error::ErrorCode::InvalidEmail => ErrorCode::EmailFormatInvalid,
client_api::error::ErrorCode::InvalidPassword => ErrorCode::PasswordFormatInvalid,
client_api::error::ErrorCode::OAuthError => ErrorCode::UserUnauthorized,
client_api::error::ErrorCode::MissingPayload => ErrorCode::MissingPayload,
client_api::error::ErrorCode::OpenError => ErrorCode::Internal,
client_api::error::ErrorCode::InvalidUrl => ErrorCode::InvalidURL,
client_api::error::ErrorCode::InvalidRequestParams => ErrorCode::InvalidParams,
client_api::error::ErrorCode::UrlMissingParameter => ErrorCode::InvalidParams,
client_api::error::ErrorCode::InvalidOAuthProvider => ErrorCode::InvalidAuthConfig,
client_api::error::ErrorCode::NotLoggedIn => ErrorCode::UserUnauthorized,
client_api::error::ErrorCode::NotEnoughPermissions => ErrorCode::NotEnoughPermissions,
client_api::error::ErrorCode::UserNameIsEmpty => ErrorCode::UserNameIsEmpty,
AppErrorCode::Ok => ErrorCode::Internal,
AppErrorCode::Unhandled => ErrorCode::Internal,
AppErrorCode::RecordNotFound => ErrorCode::RecordNotFound,
AppErrorCode::RecordAlreadyExists => ErrorCode::RecordAlreadyExists,
AppErrorCode::InvalidEmail => ErrorCode::EmailFormatInvalid,
AppErrorCode::InvalidPassword => ErrorCode::PasswordFormatInvalid,
AppErrorCode::OAuthError => ErrorCode::UserUnauthorized,
AppErrorCode::MissingPayload => ErrorCode::MissingPayload,
AppErrorCode::OpenError => ErrorCode::Internal,
AppErrorCode::InvalidUrl => ErrorCode::InvalidURL,
AppErrorCode::InvalidRequestParams => ErrorCode::InvalidParams,
AppErrorCode::UrlMissingParameter => ErrorCode::InvalidParams,
AppErrorCode::InvalidOAuthProvider => ErrorCode::InvalidAuthConfig,
AppErrorCode::NotLoggedIn => ErrorCode::UserUnauthorized,
AppErrorCode::NotEnoughPermissions => ErrorCode::NotEnoughPermissions,
_ => ErrorCode::Internal,
};