Skip to main content

BaseError

Enum BaseError 

Source
pub enum BaseError {
Show 55 variants PluginAlreadyRegistered(String), PluginNotFound(String), PluginRegisterFailed(String, String), PluginInitFailed(String, String), PluginDependencyMissing(String, String), PluginCircularDependency(String), PluginConfigInvalid(String, String), PluginShutdownFailed(String, String), DatabaseConnectionFailed(String), DatabaseAlreadyInitialized, DatabaseQueryFailed(DbError), DatabaseExecuteFailed(DbError), DatabaseInitFailed(String), DatabaseMigrationFailed(String, String), MigrationFailed(String, String, String), DatabaseNotInitialized, DatabaseTransactionFailed(DbError), RedisConnectionFailed(String), RedisAlreadyInitialized, RedisNotInitialized, RedisOperationFailed(String), HttpClientCreateFailed(Error), HttpRequestFailed(Error), HttpResponseParseFailed(String), HttpTimeout, HttpClientAlreadyInitialized, HttpClientNotInitialized, TokenKeyInvalid(String), TokenGenerateFailed(Error), TokenVerifyFailed(Error), TokenParseFailed(Error), TokenExpired, TokenTypeInvalid(String), JsonSerializeFailed(String), JsonDeserializeFailed(String), InvalidFieldType(String, String), InvalidEnumValue(String, String), StringTooLong(String, usize, usize), InvalidJsonFormat(String, String), ValidationFailed(String, String), FieldRequired(String), FieldNotFound(String, String), FieldPermissionDenied(String, String, String), ActionNotFound(String), PermissionDenied(String), Unauthorized(String), ParamMissing(String), ParamInvalid(String, String), RecordNotFound(String), UserNotFound(String), InvalidPassword, TableConfigNotSet, ConfigError(String), IoError(String), Unknown(String),
}
Expand description

系统统一错误类型

包含所有模块的错误变体,使用中文错误消息

Variants§

§

PluginAlreadyRegistered(String)

插件已注册

§

PluginNotFound(String)

插件未找到

§

PluginRegisterFailed(String, String)

插件注册失败

§

PluginInitFailed(String, String)

插件初始化失败

§

PluginDependencyMissing(String, String)

插件依赖缺失

§

PluginCircularDependency(String)

插件循环依赖

§

PluginConfigInvalid(String, String)

插件配置无效

§

PluginShutdownFailed(String, String)

插件关闭失败

§

DatabaseConnectionFailed(String)

数据库连接失败

§

DatabaseAlreadyInitialized

数据库已初始化

§

DatabaseQueryFailed(DbError)

数据库查询失败,持有底层 DbError 以保留错误链

§

DatabaseExecuteFailed(DbError)

数据库执行失败,持有底层 DbError 以保留错误链

§

DatabaseInitFailed(String)

数据库初始化失败

§

DatabaseMigrationFailed(String, String)

数据库迁移失败

§

MigrationFailed(String, String, String)

迁移失败(别名)

§

DatabaseNotInitialized

数据库未初始化

§

DatabaseTransactionFailed(DbError)

数据库事务失败,持有底层 DbError 以保留错误链

§

RedisConnectionFailed(String)

Redis 连接失败

§

RedisAlreadyInitialized

Redis 已初始化

§

RedisNotInitialized

Redis 未初始化

§

RedisOperationFailed(String)

Redis 操作失败

§

HttpClientCreateFailed(Error)

HTTP 客户端创建失败,持有底层 reqwest::Error 以保留错误链

§

HttpRequestFailed(Error)

HTTP 请求失败,持有底层 reqwest::Error 以保留错误链

§

HttpResponseParseFailed(String)

HTTP 响应解析失败

§

HttpTimeout

HTTP 超时

§

HttpClientAlreadyInitialized

HTTP 客户端已初始化

§

HttpClientNotInitialized

HTTP 客户端未初始化

§

TokenKeyInvalid(String)

Token 密钥无效

§

TokenGenerateFailed(Error)

Token 生成失败,持有底层 jsonwebtoken::errors::Error 以保留错误链

§

TokenVerifyFailed(Error)

Token 验证失败,持有底层 jsonwebtoken::errors::Error 以保留错误链

§

TokenParseFailed(Error)

Token 解析失败,持有底层 jsonwebtoken::errors::Error 以保留错误链

§

TokenExpired

Token 已过期

§

TokenTypeInvalid(String)

Token 类型无效

§

JsonSerializeFailed(String)

JSON 序列化失败

§

JsonDeserializeFailed(String)

JSON 反序列化失败

§

InvalidFieldType(String, String)

字段类型无效

§

InvalidEnumValue(String, String)

枚举值无效

§

StringTooLong(String, usize, usize)

字符串长度超出限制

§

InvalidJsonFormat(String, String)

JSON 格式无效

§

ValidationFailed(String, String)

验证失败

§

FieldRequired(String)

字段必填

§

FieldNotFound(String, String)

字段未找到

§

FieldPermissionDenied(String, String, String)

字段权限被拒绝

§

ActionNotFound(String)

Action 未找到

§

PermissionDenied(String)

权限被拒绝

§

Unauthorized(String)

未授权

§

ParamMissing(String)

参数缺失

§

ParamInvalid(String, String)

参数无效

§

RecordNotFound(String)

记录未找到

§

UserNotFound(String)

用户未找到

§

InvalidPassword

密码无效

§

TableConfigNotSet

表配置未设置

§

ConfigError(String)

配置错误

§

IoError(String)

IO 错误

§

Unknown(String)

未知错误

Implementations§

Source§

impl BaseError

Source

pub fn code(&self) -> i32

获取错误码

返回与错误类型对应的数字错误码,用于 API 响应

§错误码规范
  • 1xxxxx: 插件管理错误
  • 2xxxxx: 数据库错误
  • 3xxxxx: HTTP 客户端错误
  • 4xxxxx: Token 管理错误
  • 5xxxxx: 序列化错误
  • 6xxxxx: 字段验证错误
  • 7xxxxx: Action 系统错误
  • 9xxxxx: 通用错误
§返回
  • 错误码(非零整数)
§示例
ⓘ
use yang_base::error::BaseError;

let error = BaseError::FieldRequired("username".to_string());
assert_eq!(error.code(), 600006);

Trait Implementations§

Source§

impl Debug for BaseError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for BaseError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for BaseError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DbError> for BaseError

从 yang_db::DbError 转换为 BaseError

按 DbError 变体分类映射到对应的 BaseError 变体:

  • 查询类 → DatabaseQueryFailed
  • 执行类 → DatabaseExecuteFailed
  • 事务类 → DatabaseTransactionFailed
  • 连接类 → DatabaseConnectionFailed
  • Redis 类 → RedisOperationFailed
Source§

fn from(err: DbError) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for BaseError

从 std::io::Error 转换为 BaseError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for BaseError

从 serde_json::Error 转换为 BaseError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for BaseError

Available on crate feature http only.

从 reqwest::Error 转换为 BaseError

Source§

fn from(err: Error) -> Self

Converts to this type from the input type.
Source§

impl From<Error> for BaseError

Available on crate feature token only.

从 jsonwebtoken::errors::Error 转换为 BaseError

按 ErrorKind 分类映射:

  • ExpiredSignature → TokenExpired
  • InvalidToken / InvalidSignature → TokenVerifyFailed
  • 其他 → TokenParseFailed
Source§

fn from(err: Error) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more