146 lines
4.4 KiB
Rust
Raw Normal View History

2021-12-14 18:04:51 +08:00
use crate::protobuf::ErrorCode as ProtoBufErrorCode;
use derive_more::Display;
use flowy_derive::ProtoBuf_Enum;
use protobuf::ProtobufEnum;
use std::convert::{TryFrom, TryInto};
#[derive(Debug, Clone, ProtoBuf_Enum, Display, PartialEq, Eq)]
pub enum ErrorCode {
#[display(fmt = "Internal error")]
2022-01-23 12:14:00 +08:00
Internal = 0,
2021-12-14 18:04:51 +08:00
#[display(fmt = "UserUnauthorized")]
2022-01-23 12:14:00 +08:00
UserUnauthorized = 2,
2021-12-14 18:04:51 +08:00
#[display(fmt = "RecordNotFound")]
2022-01-23 12:14:00 +08:00
RecordNotFound = 3,
2021-12-14 18:04:51 +08:00
2022-03-19 16:23:34 +08:00
#[display(fmt = "User id is empty")]
UserIdIsEmpty = 4,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Workspace name can not be empty or whitespace")]
WorkspaceNameInvalid = 100,
#[display(fmt = "Workspace id can not be empty or whitespace")]
2022-01-23 12:14:00 +08:00
WorkspaceIdInvalid = 101,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Color style of the App is invalid")]
AppColorStyleInvalid = 102,
#[display(fmt = "Workspace desc is invalid")]
WorkspaceDescTooLong = 103,
#[display(fmt = "Workspace description too long")]
WorkspaceNameTooLong = 104,
#[display(fmt = "App id can not be empty or whitespace")]
2022-01-23 12:14:00 +08:00
AppIdInvalid = 110,
2021-12-14 18:04:51 +08:00
#[display(fmt = "App name can not be empty or whitespace")]
2022-01-23 12:14:00 +08:00
AppNameInvalid = 111,
2021-12-14 18:04:51 +08:00
#[display(fmt = "View name can not be empty or whitespace")]
2022-01-23 12:14:00 +08:00
ViewNameInvalid = 120,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Thumbnail of the view is invalid")]
ViewThumbnailInvalid = 121,
#[display(fmt = "View id can not be empty or whitespace")]
2022-01-23 12:14:00 +08:00
ViewIdInvalid = 122,
2021-12-14 18:04:51 +08:00
#[display(fmt = "View desc too long")]
2022-01-23 12:14:00 +08:00
ViewDescTooLong = 123,
2021-12-14 18:04:51 +08:00
#[display(fmt = "View data is invalid")]
2022-01-23 12:14:00 +08:00
ViewDataInvalid = 124,
2021-12-14 18:04:51 +08:00
#[display(fmt = "View name too long")]
2022-01-23 12:14:00 +08:00
ViewNameTooLong = 125,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Connection error")]
2022-01-23 12:14:00 +08:00
ConnectError = 200,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Email can not be empty or whitespace")]
2022-01-23 12:14:00 +08:00
EmailIsEmpty = 300,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Email format is not valid")]
2022-01-23 12:14:00 +08:00
EmailFormatInvalid = 301,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Email already exists")]
2022-01-23 12:14:00 +08:00
EmailAlreadyExists = 302,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Password can not be empty or whitespace")]
2022-01-23 12:14:00 +08:00
PasswordIsEmpty = 303,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Password format too long")]
2022-01-23 12:14:00 +08:00
PasswordTooLong = 304,
2021-12-14 18:04:51 +08:00
#[display(fmt = "Password contains forbidden characters.")]
PasswordContainsForbidCharacters = 305,
#[display(fmt = "Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric")]
PasswordFormatInvalid = 306,
#[display(fmt = "Password not match")]
2022-01-23 12:14:00 +08:00
PasswordNotMatch = 307,
2021-12-14 18:04:51 +08:00
#[display(fmt = "User name is too long")]
2022-01-23 12:14:00 +08:00
UserNameTooLong = 308,
2021-12-14 18:04:51 +08:00
#[display(fmt = "User name contain forbidden characters")]
UserNameContainForbiddenCharacters = 309,
#[display(fmt = "User name can not be empty or whitespace")]
2022-01-23 12:14:00 +08:00
UserNameIsEmpty = 310,
2021-12-14 18:04:51 +08:00
#[display(fmt = "user id is empty or whitespace")]
2022-01-23 12:14:00 +08:00
UserIdInvalid = 311,
2021-12-14 18:04:51 +08:00
#[display(fmt = "User not exist")]
2022-01-23 12:14:00 +08:00
UserNotExist = 312,
2022-03-16 10:02:37 +08:00
#[display(fmt = "Text is too long")]
TextTooLong = 400,
#[display(fmt = "Grid id is empty")]
GridIdIsEmpty = 410,
2022-08-16 15:49:54 +08:00
#[display(fmt = "Grid view id is empty")]
GridViewIdIsEmpty = 411,
2022-03-18 17:14:46 +08:00
#[display(fmt = "Grid block id is empty")]
BlockIdIsEmpty = 420,
2022-03-18 17:14:46 +08:00
#[display(fmt = "Row id is empty")]
RowIdIsEmpty = 430,
2022-04-05 14:25:07 +08:00
#[display(fmt = "Select option id is empty")]
OptionIdIsEmpty = 431,
#[display(fmt = "Field id is empty")]
FieldIdIsEmpty = 440,
2022-03-27 09:35:10 +08:00
#[display(fmt = "Field doesn't exist")]
FieldDoesNotExist = 441,
2022-03-29 22:58:38 +08:00
#[display(fmt = "The name of the option should not be empty")]
SelectOptionNameIsEmpty = 442,
2022-04-07 08:33:10 +08:00
#[display(fmt = "Field not exists")]
FieldNotExists = 443,
#[display(fmt = "The operation in this field is invalid")]
FieldInvalidOperation = 444,
2022-03-27 09:35:10 +08:00
#[display(fmt = "Field's type option data should not be empty")]
TypeOptionDataIsEmpty = 450,
#[display(fmt = "Group id is empty")]
GroupIdIsEmpty = 460,
2022-05-13 22:58:49 +08:00
#[display(fmt = "Invalid date time format")]
InvalidDateTimeFormat = 500,
2022-06-15 11:43:24 +08:00
#[display(fmt = "The input string is empty or contains invalid characters")]
UnexpectedEmptyString = 999,
2022-03-16 10:02:37 +08:00
#[display(fmt = "Invalid data")]
2022-05-13 22:58:49 +08:00
InvalidData = 1000,
#[display(fmt = "Out of bounds")]
OutOfBounds = 10001,
2021-12-14 18:04:51 +08:00
}
impl ErrorCode {
pub fn value(&self) -> i32 {
let code: ProtoBufErrorCode = self.clone().try_into().unwrap();
code.value()
}
pub fn from_i32(value: i32) -> Self {
match ProtoBufErrorCode::from_i32(value) {
None => ErrorCode::Internal,
Some(code) => ErrorCode::try_from(&code).unwrap(),
}
}
}