mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Refactor/crate directory (#1621)
* chore: fix wanrings * chore: remove protobuf ref in flowy-error-code * chore: remove protobuf ref in lib-ws * refactor: remove protobuf trait in flowy http model * refactor: remove flowy-error-code crate Co-authored-by: nathan <nathan@appflowy.io>
This commit is contained in:
@ -6,8 +6,7 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
flowy-derive = { path = "../../../shared-lib/flowy-derive" }
|
||||
flowy-error-code = { path = "../../../shared-lib/flowy-error-code"}
|
||||
flowy-derive = { path = "../flowy-derive" }
|
||||
lib-dispatch = { path = "../lib-dispatch" }
|
||||
protobuf = {version = "2.20.0"}
|
||||
bytes = "1.0"
|
||||
@ -15,7 +14,7 @@ anyhow = "1.0"
|
||||
thiserror = "1.0"
|
||||
|
||||
|
||||
flowy-sync = { path = "../../../shared-lib/flowy-sync", optional = true}
|
||||
flowy-sync = { path = "../flowy-sync", optional = true}
|
||||
lib-ot = { path = "../../../shared-lib/lib-ot", optional = true}
|
||||
serde_json = {version = "1.0", optional = true}
|
||||
http-flowy = { git = "https://github.com/AppFlowy-IO/AppFlowy-Server", optional = true}
|
||||
@ -29,7 +28,7 @@ ot = ["lib-ot"]
|
||||
serde = ["serde_json"]
|
||||
http_server = ["http-flowy"]
|
||||
db = ["flowy-database", "lib-sqlite", "r2d2"]
|
||||
dart = ["flowy-error-code/dart", "flowy-codegen/dart"]
|
||||
dart = ["flowy-codegen/dart"]
|
||||
|
||||
[build-dependencies]
|
||||
flowy-codegen= { path = "../../../shared-lib/flowy-codegen"}
|
||||
flowy-codegen = { path = "../flowy-codegen"}
|
||||
|
@ -1,3 +1,3 @@
|
||||
|
||||
# Check out the FlowyConfig (located in flowy_toml.rs) for more details.
|
||||
proto_input = ["src/errors.rs",]
|
||||
proto_input = ["src/errors.rs","src/code.rs"]
|
||||
|
166
frontend/rust-lib/flowy-error/src/code.rs
Normal file
166
frontend/rust-lib/flowy-error/src/code.rs
Normal file
@ -0,0 +1,166 @@
|
||||
use flowy_derive::ProtoBuf_Enum;
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Error, ProtoBuf_Enum)]
|
||||
pub enum ErrorCode {
|
||||
#[error("Internal error")]
|
||||
Internal = 0,
|
||||
|
||||
#[error("Unauthorized user")]
|
||||
UserUnauthorized = 2,
|
||||
|
||||
#[error("Record not found")]
|
||||
RecordNotFound = 3,
|
||||
|
||||
#[error("User id is empty")]
|
||||
UserIdIsEmpty = 4,
|
||||
|
||||
#[error("Workspace name can not be empty or whitespace")]
|
||||
WorkspaceNameInvalid = 5,
|
||||
|
||||
#[error("Workspace id can not be empty or whitespace")]
|
||||
WorkspaceIdInvalid = 6,
|
||||
|
||||
#[error("Color style of the App is invalid")]
|
||||
AppColorStyleInvalid = 7,
|
||||
|
||||
#[error("Workspace desc is invalid")]
|
||||
WorkspaceDescTooLong = 8,
|
||||
|
||||
#[error("Workspace description too long")]
|
||||
WorkspaceNameTooLong = 9,
|
||||
|
||||
#[error("App id can not be empty or whitespace")]
|
||||
AppIdInvalid = 10,
|
||||
|
||||
#[error("App name can not be empty or whitespace")]
|
||||
AppNameInvalid = 11,
|
||||
|
||||
#[error("View name can not be empty or whitespace")]
|
||||
ViewNameInvalid = 12,
|
||||
|
||||
#[error("Thumbnail of the view is invalid")]
|
||||
ViewThumbnailInvalid = 13,
|
||||
|
||||
#[error("View id can not be empty or whitespace")]
|
||||
ViewIdInvalid = 14,
|
||||
|
||||
#[error("View desc too long")]
|
||||
ViewDescTooLong = 15,
|
||||
|
||||
#[error("View data is invalid")]
|
||||
ViewDataInvalid = 16,
|
||||
|
||||
#[error("View name too long")]
|
||||
ViewNameTooLong = 17,
|
||||
|
||||
#[error("Http server connection error")]
|
||||
HttpServerConnectError = 18,
|
||||
|
||||
#[error("Email can not be empty or whitespace")]
|
||||
EmailIsEmpty = 19,
|
||||
|
||||
#[error("Email format is not valid")]
|
||||
EmailFormatInvalid = 20,
|
||||
|
||||
#[error("Email already exists")]
|
||||
EmailAlreadyExists = 21,
|
||||
|
||||
#[error("Password can not be empty or whitespace")]
|
||||
PasswordIsEmpty = 22,
|
||||
|
||||
#[error("Password format too long")]
|
||||
PasswordTooLong = 23,
|
||||
|
||||
#[error("Password contains forbidden characters.")]
|
||||
PasswordContainsForbidCharacters = 24,
|
||||
|
||||
#[error("Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric")]
|
||||
PasswordFormatInvalid = 25,
|
||||
|
||||
#[error("Password not match")]
|
||||
PasswordNotMatch = 26,
|
||||
|
||||
#[error("User name is too long")]
|
||||
UserNameTooLong = 27,
|
||||
|
||||
#[error("User name contain forbidden characters")]
|
||||
UserNameContainForbiddenCharacters = 28,
|
||||
|
||||
#[error("User name can not be empty or whitespace")]
|
||||
UserNameIsEmpty = 29,
|
||||
|
||||
#[error("user id is empty or whitespace")]
|
||||
UserIdInvalid = 30,
|
||||
#[error("User not exist")]
|
||||
UserNotExist = 31,
|
||||
|
||||
#[error("Text is too long")]
|
||||
TextTooLong = 32,
|
||||
|
||||
#[error("Grid id is empty")]
|
||||
GridIdIsEmpty = 33,
|
||||
|
||||
#[error("Grid view id is empty")]
|
||||
GridViewIdIsEmpty = 34,
|
||||
|
||||
#[error("Grid block id is empty")]
|
||||
BlockIdIsEmpty = 35,
|
||||
|
||||
#[error("Row id is empty")]
|
||||
RowIdIsEmpty = 36,
|
||||
|
||||
#[error("Select option id is empty")]
|
||||
OptionIdIsEmpty = 37,
|
||||
|
||||
#[error("Field id is empty")]
|
||||
FieldIdIsEmpty = 38,
|
||||
|
||||
#[error("Field doesn't exist")]
|
||||
FieldDoesNotExist = 39,
|
||||
|
||||
#[error("The name of the option should not be empty")]
|
||||
SelectOptionNameIsEmpty = 40,
|
||||
|
||||
#[error("Field not exists")]
|
||||
FieldNotExists = 41,
|
||||
|
||||
#[error("The operation in this field is invalid")]
|
||||
FieldInvalidOperation = 42,
|
||||
|
||||
#[error("Filter id is empty")]
|
||||
FilterIdIsEmpty = 43,
|
||||
|
||||
#[error("Field is not exist")]
|
||||
FieldRecordNotFound = 44,
|
||||
|
||||
#[error("Field's type-option data should not be empty")]
|
||||
TypeOptionDataIsEmpty = 45,
|
||||
|
||||
#[error("Group id is empty")]
|
||||
GroupIdIsEmpty = 46,
|
||||
|
||||
#[error("Invalid date time format")]
|
||||
InvalidDateTimeFormat = 47,
|
||||
|
||||
#[error("The input string is empty or contains invalid characters")]
|
||||
UnexpectedEmptyString = 48,
|
||||
|
||||
#[error("Invalid data")]
|
||||
InvalidData = 49,
|
||||
|
||||
#[error("Serde")]
|
||||
Serde = 50,
|
||||
|
||||
#[error("Protobuf serde")]
|
||||
ProtobufSerde = 51,
|
||||
|
||||
#[error("Out of bounds")]
|
||||
OutOfBounds = 52,
|
||||
}
|
||||
|
||||
impl ErrorCode {
|
||||
pub fn value(&self) -> i32 {
|
||||
self.clone() as i32
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
use crate::ErrorCode;
|
||||
use anyhow::Result;
|
||||
use bytes::Bytes;
|
||||
use flowy_derive::ProtoBuf;
|
||||
use flowy_error_code::ErrorCode;
|
||||
use lib_dispatch::prelude::{AFPluginEventResponse, ResponseBuilder};
|
||||
use std::{convert::TryInto, fmt::Debug};
|
||||
use thiserror::Error;
|
||||
@ -30,7 +30,7 @@ macro_rules! static_flowy_error {
|
||||
impl FlowyError {
|
||||
pub fn new(code: ErrorCode, msg: &str) -> Self {
|
||||
Self {
|
||||
code: code.value(),
|
||||
code: code.value() as i32,
|
||||
msg: msg.to_owned(),
|
||||
}
|
||||
}
|
||||
@ -53,7 +53,7 @@ impl FlowyError {
|
||||
static_flowy_error!(view_desc, ErrorCode::ViewDescTooLong);
|
||||
static_flowy_error!(view_data, ErrorCode::ViewDataInvalid);
|
||||
static_flowy_error!(unauthorized, ErrorCode::UserUnauthorized);
|
||||
static_flowy_error!(connection, ErrorCode::ConnectError);
|
||||
static_flowy_error!(connection, ErrorCode::HttpServerConnectError);
|
||||
static_flowy_error!(email_empty, ErrorCode::EmailIsEmpty);
|
||||
static_flowy_error!(email_format, ErrorCode::EmailFormatInvalid);
|
||||
static_flowy_error!(email_exist, ErrorCode::EmailAlreadyExists);
|
||||
@ -77,7 +77,7 @@ impl FlowyError {
|
||||
impl std::convert::From<ErrorCode> for FlowyError {
|
||||
fn from(code: ErrorCode) -> Self {
|
||||
FlowyError {
|
||||
code: code.value(),
|
||||
code: code.value() as i32,
|
||||
msg: format!("{}", code),
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::FlowyError;
|
||||
use flowy_error_code::ErrorCode;
|
||||
use crate::{ErrorCode, FlowyError};
|
||||
use http_flowy::errors::{ErrorCode as ServerErrorCode, ServerError};
|
||||
|
||||
impl std::convert::From<ServerError> for FlowyError {
|
||||
@ -15,7 +14,7 @@ fn server_error_to_flowy_error(code: ServerErrorCode) -> ErrorCode {
|
||||
ServerErrorCode::PasswordNotMatch => ErrorCode::PasswordNotMatch,
|
||||
ServerErrorCode::RecordNotFound => ErrorCode::RecordNotFound,
|
||||
ServerErrorCode::ConnectRefused | ServerErrorCode::ConnectTimeout | ServerErrorCode::ConnectClose => {
|
||||
ErrorCode::ConnectError
|
||||
ErrorCode::HttpServerConnectError
|
||||
}
|
||||
_ => ErrorCode::Internal,
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
mod code;
|
||||
mod errors;
|
||||
mod ext;
|
||||
pub mod protobuf;
|
||||
|
||||
pub use code::*;
|
||||
pub use errors::*;
|
||||
pub use flowy_error_code::ErrorCode;
|
||||
|
Reference in New Issue
Block a user