2023-11-05 14:00:24 +08:00
|
|
|
use client_api::error::{AppResponseError, ErrorCode as AppErrorCode};
|
2023-09-17 17:14:34 +08:00
|
|
|
|
|
|
|
use crate::{ErrorCode, FlowyError};
|
|
|
|
|
2023-11-05 14:00:24 +08:00
|
|
|
impl From<AppResponseError> for FlowyError {
|
|
|
|
fn from(error: AppResponseError) -> Self {
|
2023-09-17 17:14:34 +08:00
|
|
|
let code = match error.code {
|
2023-11-05 14:00:24 +08:00
|
|
|
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,
|
2023-10-02 17:22:22 +08:00
|
|
|
_ => ErrorCode::Internal,
|
2023-09-17 17:14:34 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
FlowyError::new(code, error.message)
|
|
|
|
}
|
|
|
|
}
|