mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: run rustfmt with custom defined fmt configuration (#1848)
* chore: update rustfmt * chore: apply rustfmt format
This commit is contained in:
@ -1,3 +1,3 @@
|
||||
fn main() {
|
||||
flowy_codegen::protobuf_file::gen("flowy-error");
|
||||
flowy_codegen::protobuf_file::gen("flowy-error");
|
||||
}
|
||||
|
@ -5,189 +5,191 @@ use thiserror::Error;
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Error, Serialize_repr, Deserialize_repr, ProtoBuf_Enum)]
|
||||
#[repr(u8)]
|
||||
pub enum ErrorCode {
|
||||
#[error("Internal error")]
|
||||
Internal = 0,
|
||||
#[error("Internal error")]
|
||||
Internal = 0,
|
||||
|
||||
#[error("Unauthorized user")]
|
||||
UserUnauthorized = 2,
|
||||
#[error("Unauthorized user")]
|
||||
UserUnauthorized = 2,
|
||||
|
||||
#[error("Record not found")]
|
||||
RecordNotFound = 3,
|
||||
#[error("Record not found")]
|
||||
RecordNotFound = 3,
|
||||
|
||||
#[error("User id is empty")]
|
||||
UserIdIsEmpty = 4,
|
||||
#[error("User id is empty")]
|
||||
UserIdIsEmpty = 4,
|
||||
|
||||
#[error("Workspace name can not be empty or whitespace")]
|
||||
WorkspaceNameInvalid = 5,
|
||||
#[error("Workspace name can not be empty or whitespace")]
|
||||
WorkspaceNameInvalid = 5,
|
||||
|
||||
#[error("Workspace id can not be empty or whitespace")]
|
||||
WorkspaceIdInvalid = 6,
|
||||
#[error("Workspace id can not be empty or whitespace")]
|
||||
WorkspaceIdInvalid = 6,
|
||||
|
||||
#[error("Color style of the App is invalid")]
|
||||
AppColorStyleInvalid = 7,
|
||||
#[error("Color style of the App is invalid")]
|
||||
AppColorStyleInvalid = 7,
|
||||
|
||||
#[error("Workspace desc is invalid")]
|
||||
WorkspaceDescTooLong = 8,
|
||||
#[error("Workspace desc is invalid")]
|
||||
WorkspaceDescTooLong = 8,
|
||||
|
||||
#[error("Workspace description too long")]
|
||||
WorkspaceNameTooLong = 9,
|
||||
#[error("Workspace description too long")]
|
||||
WorkspaceNameTooLong = 9,
|
||||
|
||||
#[error("App id can not be empty or whitespace")]
|
||||
AppIdInvalid = 10,
|
||||
#[error("App id can not be empty or whitespace")]
|
||||
AppIdInvalid = 10,
|
||||
|
||||
#[error("App name can not be empty or whitespace")]
|
||||
AppNameInvalid = 11,
|
||||
#[error("App name can not be empty or whitespace")]
|
||||
AppNameInvalid = 11,
|
||||
|
||||
#[error("View name can not be empty or whitespace")]
|
||||
ViewNameInvalid = 12,
|
||||
#[error("View name can not be empty or whitespace")]
|
||||
ViewNameInvalid = 12,
|
||||
|
||||
#[error("Thumbnail of the view is invalid")]
|
||||
ViewThumbnailInvalid = 13,
|
||||
#[error("Thumbnail of the view is invalid")]
|
||||
ViewThumbnailInvalid = 13,
|
||||
|
||||
#[error("View id can not be empty or whitespace")]
|
||||
ViewIdInvalid = 14,
|
||||
#[error("View id can not be empty or whitespace")]
|
||||
ViewIdInvalid = 14,
|
||||
|
||||
#[error("View desc too long")]
|
||||
ViewDescTooLong = 15,
|
||||
#[error("View desc too long")]
|
||||
ViewDescTooLong = 15,
|
||||
|
||||
#[error("View data is invalid")]
|
||||
ViewDataInvalid = 16,
|
||||
#[error("View data is invalid")]
|
||||
ViewDataInvalid = 16,
|
||||
|
||||
#[error("View name too long")]
|
||||
ViewNameTooLong = 17,
|
||||
#[error("View name too long")]
|
||||
ViewNameTooLong = 17,
|
||||
|
||||
#[error("Http server connection error")]
|
||||
HttpServerConnectError = 18,
|
||||
#[error("Http server connection error")]
|
||||
HttpServerConnectError = 18,
|
||||
|
||||
#[error("Email can not be empty or whitespace")]
|
||||
EmailIsEmpty = 19,
|
||||
#[error("Email can not be empty or whitespace")]
|
||||
EmailIsEmpty = 19,
|
||||
|
||||
#[error("Email format is not valid")]
|
||||
EmailFormatInvalid = 20,
|
||||
#[error("Email format is not valid")]
|
||||
EmailFormatInvalid = 20,
|
||||
|
||||
#[error("Email already exists")]
|
||||
EmailAlreadyExists = 21,
|
||||
#[error("Email already exists")]
|
||||
EmailAlreadyExists = 21,
|
||||
|
||||
#[error("Password can not be empty or whitespace")]
|
||||
PasswordIsEmpty = 22,
|
||||
#[error("Password can not be empty or whitespace")]
|
||||
PasswordIsEmpty = 22,
|
||||
|
||||
#[error("Password format too long")]
|
||||
PasswordTooLong = 23,
|
||||
#[error("Password format too long")]
|
||||
PasswordTooLong = 23,
|
||||
|
||||
#[error("Password contains forbidden characters.")]
|
||||
PasswordContainsForbidCharacters = 24,
|
||||
#[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 should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric"
|
||||
)]
|
||||
PasswordFormatInvalid = 25,
|
||||
|
||||
#[error("Password not match")]
|
||||
PasswordNotMatch = 26,
|
||||
#[error("Password not match")]
|
||||
PasswordNotMatch = 26,
|
||||
|
||||
#[error("User name is too long")]
|
||||
UserNameTooLong = 27,
|
||||
#[error("User name is too long")]
|
||||
UserNameTooLong = 27,
|
||||
|
||||
#[error("User name contain forbidden characters")]
|
||||
UserNameContainForbiddenCharacters = 28,
|
||||
#[error("User name contain forbidden characters")]
|
||||
UserNameContainForbiddenCharacters = 28,
|
||||
|
||||
#[error("User name can not be empty or whitespace")]
|
||||
UserNameIsEmpty = 29,
|
||||
#[error("User name can not be empty or whitespace")]
|
||||
UserNameIsEmpty = 29,
|
||||
|
||||
#[error("user id is empty or whitespace")]
|
||||
UserIdInvalid = 30,
|
||||
#[error("user id is empty or whitespace")]
|
||||
UserIdInvalid = 30,
|
||||
|
||||
#[error("User not exist")]
|
||||
UserNotExist = 31,
|
||||
#[error("User not exist")]
|
||||
UserNotExist = 31,
|
||||
|
||||
#[error("Text is too long")]
|
||||
TextTooLong = 32,
|
||||
#[error("Text is too long")]
|
||||
TextTooLong = 32,
|
||||
|
||||
#[error("Database id is empty")]
|
||||
DatabaseIdIsEmpty = 33,
|
||||
#[error("Database id is empty")]
|
||||
DatabaseIdIsEmpty = 33,
|
||||
|
||||
#[error("Grid view id is empty")]
|
||||
DatabaseViewIdIsEmpty = 34,
|
||||
#[error("Grid view id is empty")]
|
||||
DatabaseViewIdIsEmpty = 34,
|
||||
|
||||
#[error("Grid block id is empty")]
|
||||
BlockIdIsEmpty = 35,
|
||||
#[error("Grid block id is empty")]
|
||||
BlockIdIsEmpty = 35,
|
||||
|
||||
#[error("Row id is empty")]
|
||||
RowIdIsEmpty = 36,
|
||||
#[error("Row id is empty")]
|
||||
RowIdIsEmpty = 36,
|
||||
|
||||
#[error("Select option id is empty")]
|
||||
OptionIdIsEmpty = 37,
|
||||
#[error("Select option id is empty")]
|
||||
OptionIdIsEmpty = 37,
|
||||
|
||||
#[error("Field id is empty")]
|
||||
FieldIdIsEmpty = 38,
|
||||
#[error("Field id is empty")]
|
||||
FieldIdIsEmpty = 38,
|
||||
|
||||
#[error("Field doesn't exist")]
|
||||
FieldDoesNotExist = 39,
|
||||
#[error("Field doesn't exist")]
|
||||
FieldDoesNotExist = 39,
|
||||
|
||||
#[error("The name of the option should not be empty")]
|
||||
SelectOptionNameIsEmpty = 40,
|
||||
#[error("The name of the option should not be empty")]
|
||||
SelectOptionNameIsEmpty = 40,
|
||||
|
||||
#[error("Field not exists")]
|
||||
FieldNotExists = 41,
|
||||
#[error("Field not exists")]
|
||||
FieldNotExists = 41,
|
||||
|
||||
#[error("The operation in this field is invalid")]
|
||||
FieldInvalidOperation = 42,
|
||||
#[error("The operation in this field is invalid")]
|
||||
FieldInvalidOperation = 42,
|
||||
|
||||
#[error("Filter id is empty")]
|
||||
FilterIdIsEmpty = 43,
|
||||
#[error("Filter id is empty")]
|
||||
FilterIdIsEmpty = 43,
|
||||
|
||||
#[error("Field is not exist")]
|
||||
FieldRecordNotFound = 44,
|
||||
#[error("Field is not exist")]
|
||||
FieldRecordNotFound = 44,
|
||||
|
||||
#[error("Field's type-option data should not be empty")]
|
||||
TypeOptionDataIsEmpty = 45,
|
||||
#[error("Field's type-option data should not be empty")]
|
||||
TypeOptionDataIsEmpty = 45,
|
||||
|
||||
#[error("Group id is empty")]
|
||||
GroupIdIsEmpty = 46,
|
||||
#[error("Group id is empty")]
|
||||
GroupIdIsEmpty = 46,
|
||||
|
||||
#[error("Invalid date time format")]
|
||||
InvalidDateTimeFormat = 47,
|
||||
#[error("Invalid date time format")]
|
||||
InvalidDateTimeFormat = 47,
|
||||
|
||||
#[error("The input string is empty or contains invalid characters")]
|
||||
UnexpectedEmptyString = 48,
|
||||
#[error("The input string is empty or contains invalid characters")]
|
||||
UnexpectedEmptyString = 48,
|
||||
|
||||
#[error("Invalid data")]
|
||||
InvalidData = 49,
|
||||
#[error("Invalid data")]
|
||||
InvalidData = 49,
|
||||
|
||||
#[error("Serde")]
|
||||
Serde = 50,
|
||||
#[error("Serde")]
|
||||
Serde = 50,
|
||||
|
||||
#[error("Protobuf serde")]
|
||||
ProtobufSerde = 51,
|
||||
#[error("Protobuf serde")]
|
||||
ProtobufSerde = 51,
|
||||
|
||||
#[error("Out of bounds")]
|
||||
OutOfBounds = 52,
|
||||
#[error("Out of bounds")]
|
||||
OutOfBounds = 52,
|
||||
|
||||
#[error("Sort id is empty")]
|
||||
SortIdIsEmpty = 53,
|
||||
#[error("Sort id is empty")]
|
||||
SortIdIsEmpty = 53,
|
||||
|
||||
#[error("Connect refused")]
|
||||
ConnectRefused = 54,
|
||||
#[error("Connect refused")]
|
||||
ConnectRefused = 54,
|
||||
|
||||
#[error("Connection timeout")]
|
||||
ConnectTimeout = 55,
|
||||
#[error("Connection timeout")]
|
||||
ConnectTimeout = 55,
|
||||
|
||||
#[error("Connection closed")]
|
||||
ConnectClose = 56,
|
||||
#[error("Connection closed")]
|
||||
ConnectClose = 56,
|
||||
|
||||
#[error("Connection canceled")]
|
||||
ConnectCancel = 57,
|
||||
#[error("Connection canceled")]
|
||||
ConnectCancel = 57,
|
||||
|
||||
#[error("Sql error")]
|
||||
SqlError = 58,
|
||||
#[error("Sql error")]
|
||||
SqlError = 58,
|
||||
|
||||
#[error("Http request error")]
|
||||
HttpError = 59,
|
||||
#[error("Http request error")]
|
||||
HttpError = 59,
|
||||
|
||||
#[error("Payload should not be empty")]
|
||||
UnexpectedEmptyPayload = 60,
|
||||
#[error("Payload should not be empty")]
|
||||
UnexpectedEmptyPayload = 60,
|
||||
}
|
||||
|
||||
impl ErrorCode {
|
||||
pub fn value(&self) -> i32 {
|
||||
self.clone() as i32
|
||||
}
|
||||
pub fn value(&self) -> i32 {
|
||||
self.clone() as i32
|
||||
}
|
||||
}
|
||||
|
@ -9,99 +9,105 @@ pub type FlowyResult<T> = anyhow::Result<T, FlowyError>;
|
||||
#[derive(Debug, Default, Clone, ProtoBuf, Error)]
|
||||
#[error("{code:?}: {msg}")]
|
||||
pub struct FlowyError {
|
||||
#[pb(index = 1)]
|
||||
pub code: i32,
|
||||
#[pb(index = 1)]
|
||||
pub code: i32,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub msg: String,
|
||||
#[pb(index = 2)]
|
||||
pub msg: String,
|
||||
}
|
||||
|
||||
macro_rules! static_flowy_error {
|
||||
($name:ident, $code:expr) => {
|
||||
#[allow(non_snake_case, missing_docs)]
|
||||
pub fn $name() -> FlowyError {
|
||||
$code.into()
|
||||
}
|
||||
};
|
||||
($name:ident, $code:expr) => {
|
||||
#[allow(non_snake_case, missing_docs)]
|
||||
pub fn $name() -> FlowyError {
|
||||
$code.into()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
impl FlowyError {
|
||||
pub fn new(code: ErrorCode, msg: &str) -> Self {
|
||||
Self {
|
||||
code: code.value() as i32,
|
||||
msg: msg.to_owned(),
|
||||
}
|
||||
}
|
||||
pub fn context<T: Debug>(mut self, error: T) -> Self {
|
||||
self.msg = format!("{:?}", error);
|
||||
self
|
||||
pub fn new(code: ErrorCode, msg: &str) -> Self {
|
||||
Self {
|
||||
code: code.value() as i32,
|
||||
msg: msg.to_owned(),
|
||||
}
|
||||
}
|
||||
pub fn context<T: Debug>(mut self, error: T) -> Self {
|
||||
self.msg = format!("{:?}", error);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_record_not_found(&self) -> bool {
|
||||
self.code == ErrorCode::RecordNotFound.value()
|
||||
}
|
||||
pub fn is_record_not_found(&self) -> bool {
|
||||
self.code == ErrorCode::RecordNotFound.value()
|
||||
}
|
||||
|
||||
static_flowy_error!(internal, ErrorCode::Internal);
|
||||
static_flowy_error!(record_not_found, ErrorCode::RecordNotFound);
|
||||
static_flowy_error!(workspace_name, ErrorCode::WorkspaceNameInvalid);
|
||||
static_flowy_error!(workspace_id, ErrorCode::WorkspaceIdInvalid);
|
||||
static_flowy_error!(color_style, ErrorCode::AppColorStyleInvalid);
|
||||
static_flowy_error!(workspace_desc, ErrorCode::WorkspaceDescTooLong);
|
||||
static_flowy_error!(app_name, ErrorCode::AppNameInvalid);
|
||||
static_flowy_error!(invalid_app_id, ErrorCode::AppIdInvalid);
|
||||
static_flowy_error!(view_name, ErrorCode::ViewNameInvalid);
|
||||
static_flowy_error!(view_thumbnail, ErrorCode::ViewThumbnailInvalid);
|
||||
static_flowy_error!(invalid_view_id, ErrorCode::ViewIdInvalid);
|
||||
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::HttpServerConnectError);
|
||||
static_flowy_error!(email_empty, ErrorCode::EmailIsEmpty);
|
||||
static_flowy_error!(email_format, ErrorCode::EmailFormatInvalid);
|
||||
static_flowy_error!(email_exist, ErrorCode::EmailAlreadyExists);
|
||||
static_flowy_error!(password_empty, ErrorCode::PasswordIsEmpty);
|
||||
static_flowy_error!(passworkd_too_long, ErrorCode::PasswordTooLong);
|
||||
static_flowy_error!(password_forbid_char, ErrorCode::PasswordContainsForbidCharacters);
|
||||
static_flowy_error!(password_format, ErrorCode::PasswordFormatInvalid);
|
||||
static_flowy_error!(password_not_match, ErrorCode::PasswordNotMatch);
|
||||
static_flowy_error!(name_too_long, ErrorCode::UserNameTooLong);
|
||||
static_flowy_error!(name_forbid_char, ErrorCode::UserNameContainForbiddenCharacters);
|
||||
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::InvalidData);
|
||||
static_flowy_error!(out_of_bounds, ErrorCode::OutOfBounds);
|
||||
static_flowy_error!(serde, ErrorCode::Serde);
|
||||
static_flowy_error!(field_record_not_found, ErrorCode::FieldRecordNotFound);
|
||||
static_flowy_error!(payload_none, ErrorCode::UnexpectedEmptyPayload);
|
||||
static_flowy_error!(http, ErrorCode::HttpError);
|
||||
static_flowy_error!(internal, ErrorCode::Internal);
|
||||
static_flowy_error!(record_not_found, ErrorCode::RecordNotFound);
|
||||
static_flowy_error!(workspace_name, ErrorCode::WorkspaceNameInvalid);
|
||||
static_flowy_error!(workspace_id, ErrorCode::WorkspaceIdInvalid);
|
||||
static_flowy_error!(color_style, ErrorCode::AppColorStyleInvalid);
|
||||
static_flowy_error!(workspace_desc, ErrorCode::WorkspaceDescTooLong);
|
||||
static_flowy_error!(app_name, ErrorCode::AppNameInvalid);
|
||||
static_flowy_error!(invalid_app_id, ErrorCode::AppIdInvalid);
|
||||
static_flowy_error!(view_name, ErrorCode::ViewNameInvalid);
|
||||
static_flowy_error!(view_thumbnail, ErrorCode::ViewThumbnailInvalid);
|
||||
static_flowy_error!(invalid_view_id, ErrorCode::ViewIdInvalid);
|
||||
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::HttpServerConnectError);
|
||||
static_flowy_error!(email_empty, ErrorCode::EmailIsEmpty);
|
||||
static_flowy_error!(email_format, ErrorCode::EmailFormatInvalid);
|
||||
static_flowy_error!(email_exist, ErrorCode::EmailAlreadyExists);
|
||||
static_flowy_error!(password_empty, ErrorCode::PasswordIsEmpty);
|
||||
static_flowy_error!(passworkd_too_long, ErrorCode::PasswordTooLong);
|
||||
static_flowy_error!(
|
||||
password_forbid_char,
|
||||
ErrorCode::PasswordContainsForbidCharacters
|
||||
);
|
||||
static_flowy_error!(password_format, ErrorCode::PasswordFormatInvalid);
|
||||
static_flowy_error!(password_not_match, ErrorCode::PasswordNotMatch);
|
||||
static_flowy_error!(name_too_long, ErrorCode::UserNameTooLong);
|
||||
static_flowy_error!(
|
||||
name_forbid_char,
|
||||
ErrorCode::UserNameContainForbiddenCharacters
|
||||
);
|
||||
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::InvalidData);
|
||||
static_flowy_error!(out_of_bounds, ErrorCode::OutOfBounds);
|
||||
static_flowy_error!(serde, ErrorCode::Serde);
|
||||
static_flowy_error!(field_record_not_found, ErrorCode::FieldRecordNotFound);
|
||||
static_flowy_error!(payload_none, ErrorCode::UnexpectedEmptyPayload);
|
||||
static_flowy_error!(http, ErrorCode::HttpError);
|
||||
}
|
||||
|
||||
impl std::convert::From<ErrorCode> for FlowyError {
|
||||
fn from(code: ErrorCode) -> Self {
|
||||
FlowyError {
|
||||
code: code.value() as i32,
|
||||
msg: format!("{}", code),
|
||||
}
|
||||
fn from(code: ErrorCode) -> Self {
|
||||
FlowyError {
|
||||
code: code.value() as i32,
|
||||
msg: format!("{}", code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn internal_error<T>(e: T) -> FlowyError
|
||||
where
|
||||
T: std::fmt::Debug,
|
||||
T: std::fmt::Debug,
|
||||
{
|
||||
FlowyError::internal().context(e)
|
||||
FlowyError::internal().context(e)
|
||||
}
|
||||
|
||||
impl std::convert::From<std::io::Error> for FlowyError {
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
FlowyError::internal().context(error)
|
||||
}
|
||||
fn from(error: std::io::Error) -> Self {
|
||||
FlowyError::internal().context(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<protobuf::ProtobufError> for FlowyError {
|
||||
fn from(e: protobuf::ProtobufError) -> Self {
|
||||
FlowyError::internal().context(e)
|
||||
}
|
||||
fn from(e: protobuf::ProtobufError) -> Self {
|
||||
FlowyError::internal().context(e)
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::FlowyError;
|
||||
|
||||
impl std::convert::From<flowy_sqlite::Error> for FlowyError {
|
||||
fn from(error: flowy_sqlite::Error) -> Self {
|
||||
FlowyError::internal().context(error)
|
||||
}
|
||||
fn from(error: flowy_sqlite::Error) -> Self {
|
||||
FlowyError::internal().context(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<::r2d2::Error> for FlowyError {
|
||||
fn from(error: r2d2::Error) -> Self {
|
||||
FlowyError::internal().context(error)
|
||||
}
|
||||
fn from(error: r2d2::Error) -> Self {
|
||||
FlowyError::internal().context(error)
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ use bytes::Bytes;
|
||||
use lib_dispatch::prelude::{AFPluginEventResponse, ResponseBuilder};
|
||||
use std::convert::TryInto;
|
||||
impl lib_dispatch::Error for FlowyError {
|
||||
fn as_response(&self) -> AFPluginEventResponse {
|
||||
let bytes: Bytes = self.clone().try_into().unwrap();
|
||||
ResponseBuilder::Err().data(bytes).build()
|
||||
}
|
||||
fn as_response(&self) -> AFPluginEventResponse {
|
||||
let bytes: Bytes = self.clone().try_into().unwrap();
|
||||
ResponseBuilder::Err().data(bytes).build()
|
||||
}
|
||||
}
|
||||
|
@ -2,15 +2,15 @@ use crate::code::ErrorCode;
|
||||
use http_error_code::ErrorCode as ServerErrorCode;
|
||||
|
||||
impl std::convert::From<ServerErrorCode> for ErrorCode {
|
||||
fn from(code: ServerErrorCode) -> Self {
|
||||
match code {
|
||||
ServerErrorCode::UserUnauthorized => ErrorCode::UserUnauthorized,
|
||||
ServerErrorCode::PasswordNotMatch => ErrorCode::PasswordNotMatch,
|
||||
ServerErrorCode::RecordNotFound => ErrorCode::RecordNotFound,
|
||||
ServerErrorCode::ConnectRefused | ServerErrorCode::ConnectTimeout | ServerErrorCode::ConnectClose => {
|
||||
ErrorCode::HttpServerConnectError
|
||||
}
|
||||
_ => ErrorCode::Internal,
|
||||
}
|
||||
fn from(code: ServerErrorCode) -> Self {
|
||||
match code {
|
||||
ServerErrorCode::UserUnauthorized => ErrorCode::UserUnauthorized,
|
||||
ServerErrorCode::PasswordNotMatch => ErrorCode::PasswordNotMatch,
|
||||
ServerErrorCode::RecordNotFound => ErrorCode::RecordNotFound,
|
||||
ServerErrorCode::ConnectRefused
|
||||
| ServerErrorCode::ConnectTimeout
|
||||
| ServerErrorCode::ConnectClose => ErrorCode::HttpServerConnectError,
|
||||
_ => ErrorCode::Internal,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::FlowyError;
|
||||
|
||||
impl std::convert::From<lib_ot::errors::OTError> for FlowyError {
|
||||
fn from(error: lib_ot::errors::OTError) -> Self {
|
||||
FlowyError::internal().context(error.msg)
|
||||
}
|
||||
fn from(error: lib_ot::errors::OTError) -> Self {
|
||||
FlowyError::internal().context(error.msg)
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use crate::FlowyError;
|
||||
use reqwest::Error;
|
||||
|
||||
impl std::convert::From<reqwest::Error> for FlowyError {
|
||||
fn from(error: Error) -> Self {
|
||||
FlowyError::connection().context(error)
|
||||
}
|
||||
fn from(error: Error) -> Self {
|
||||
FlowyError::connection().context(error)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::FlowyError;
|
||||
|
||||
impl std::convert::From<serde_json::Error> for FlowyError {
|
||||
fn from(error: serde_json::Error) -> Self {
|
||||
FlowyError::serde().context(error)
|
||||
}
|
||||
fn from(error: serde_json::Error) -> Self {
|
||||
FlowyError::serde().context(error)
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ use crate::FlowyError;
|
||||
use flowy_client_sync::errors::ErrorCode;
|
||||
|
||||
impl std::convert::From<flowy_client_sync::errors::SyncError> for FlowyError {
|
||||
fn from(error: flowy_client_sync::errors::SyncError) -> Self {
|
||||
match error.code {
|
||||
ErrorCode::RecordNotFound => FlowyError::record_not_found().context(error.msg),
|
||||
_ => FlowyError::internal().context(error.msg),
|
||||
}
|
||||
fn from(error: flowy_client_sync::errors::SyncError) -> Self {
|
||||
match error.code {
|
||||
ErrorCode::RecordNotFound => FlowyError::record_not_found().context(error.msg),
|
||||
_ => FlowyError::internal().context(error.msg),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,22 +2,26 @@ use crate::code::ErrorCode;
|
||||
use user_model::errors::UserErrorCode;
|
||||
|
||||
impl std::convert::From<UserErrorCode> for ErrorCode {
|
||||
fn from(code: UserErrorCode) -> Self {
|
||||
match code {
|
||||
UserErrorCode::Internal => ErrorCode::Internal,
|
||||
UserErrorCode::WorkspaceIdInvalid => ErrorCode::WorkspaceIdInvalid,
|
||||
UserErrorCode::EmailIsEmpty => ErrorCode::EmailIsEmpty,
|
||||
UserErrorCode::EmailFormatInvalid => ErrorCode::EmailFormatInvalid,
|
||||
UserErrorCode::UserIdInvalid => ErrorCode::UserIdInvalid,
|
||||
UserErrorCode::UserNameContainForbiddenCharacters => ErrorCode::UserNameContainForbiddenCharacters,
|
||||
UserErrorCode::UserNameIsEmpty => ErrorCode::UserNameIsEmpty,
|
||||
UserErrorCode::UserNotExist => ErrorCode::UserNotExist,
|
||||
UserErrorCode::PasswordIsEmpty => ErrorCode::PasswordIsEmpty,
|
||||
UserErrorCode::PasswordTooLong => ErrorCode::PasswordTooLong,
|
||||
UserErrorCode::PasswordContainsForbidCharacters => ErrorCode::PasswordContainsForbidCharacters,
|
||||
UserErrorCode::PasswordFormatInvalid => ErrorCode::PasswordFormatInvalid,
|
||||
UserErrorCode::PasswordNotMatch => ErrorCode::PasswordNotMatch,
|
||||
UserErrorCode::UserNameTooLong => ErrorCode::UserNameTooLong,
|
||||
}
|
||||
fn from(code: UserErrorCode) -> Self {
|
||||
match code {
|
||||
UserErrorCode::Internal => ErrorCode::Internal,
|
||||
UserErrorCode::WorkspaceIdInvalid => ErrorCode::WorkspaceIdInvalid,
|
||||
UserErrorCode::EmailIsEmpty => ErrorCode::EmailIsEmpty,
|
||||
UserErrorCode::EmailFormatInvalid => ErrorCode::EmailFormatInvalid,
|
||||
UserErrorCode::UserIdInvalid => ErrorCode::UserIdInvalid,
|
||||
UserErrorCode::UserNameContainForbiddenCharacters => {
|
||||
ErrorCode::UserNameContainForbiddenCharacters
|
||||
},
|
||||
UserErrorCode::UserNameIsEmpty => ErrorCode::UserNameIsEmpty,
|
||||
UserErrorCode::UserNotExist => ErrorCode::UserNotExist,
|
||||
UserErrorCode::PasswordIsEmpty => ErrorCode::PasswordIsEmpty,
|
||||
UserErrorCode::PasswordTooLong => ErrorCode::PasswordTooLong,
|
||||
UserErrorCode::PasswordContainsForbidCharacters => {
|
||||
ErrorCode::PasswordContainsForbidCharacters
|
||||
},
|
||||
UserErrorCode::PasswordFormatInvalid => ErrorCode::PasswordFormatInvalid,
|
||||
UserErrorCode::PasswordNotMatch => ErrorCode::PasswordNotMatch,
|
||||
UserErrorCode::UserNameTooLong => ErrorCode::UserNameTooLong,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,9 @@ use crate::FlowyError;
|
||||
use flowy_client_ws::WSErrorCode;
|
||||
|
||||
impl std::convert::From<WSErrorCode> for FlowyError {
|
||||
fn from(code: WSErrorCode) -> Self {
|
||||
match code {
|
||||
WSErrorCode::Internal => FlowyError::internal().context(code),
|
||||
}
|
||||
fn from(code: WSErrorCode) -> Self {
|
||||
match code {
|
||||
WSErrorCode::Internal => FlowyError::internal().context(code),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user