pub enum BaseError {
Show 53 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(String),
DatabaseExecuteFailed(String),
DatabaseInitFailed(String),
DatabaseMigrationFailed(String, String),
MigrationFailed(String, String, String),
DatabaseNotInitialized,
DatabaseTransactionFailed(String),
RedisConnectionFailed(String),
RedisAlreadyInitialized,
RedisNotInitialized,
RedisOperationFailed(String),
HttpClientCreateFailed(String),
HttpRequestFailed(String),
HttpResponseParseFailed(String),
HttpTimeout,
TokenKeyInvalid(String),
TokenGenerateFailed(String),
TokenVerifyFailed(String),
TokenParseFailed(String),
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(String)
数据库查询失败
DatabaseExecuteFailed(String)
数据库执行失败
DatabaseInitFailed(String)
数据库初始化失败
DatabaseMigrationFailed(String, String)
数据库迁移失败
MigrationFailed(String, String, String)
迁移失败(别名)
DatabaseNotInitialized
数据库未初始化
DatabaseTransactionFailed(String)
数据库事务失败
RedisConnectionFailed(String)
Redis 连接失败
RedisAlreadyInitialized
Redis 已初始化
RedisNotInitialized
Redis 未初始化
RedisOperationFailed(String)
Redis 操作失败
HttpClientCreateFailed(String)
HTTP 客户端创建失败
HttpRequestFailed(String)
HTTP 请求失败
HttpResponseParseFailed(String)
HTTP 响应解析失败
HttpTimeout
HTTP 超时
TokenKeyInvalid(String)
Token 密钥无效
TokenGenerateFailed(String)
Token 生成失败
TokenVerifyFailed(String)
Token 验证失败
TokenParseFailed(String)
Token 解析失败
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)
权限被拒绝
未授权
ParamMissing(String)
参数缺失
ParamInvalid(String, String)
参数无效
RecordNotFound(String)
记录未找到
UserNotFound(String)
用户未找到
InvalidPassword
密码无效
TableConfigNotSet
表配置未设置
ConfigError(String)
配置错误
IoError(String)
IO 错误
Unknown(String)
未知错误
Implementations§
Source§impl BaseError
impl BaseError
Sourcepub fn code(&self) -> i32
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 Error for BaseError
impl Error for BaseError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
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
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for BaseError
impl RefUnwindSafe for BaseError
impl Send for BaseError
impl Sync for BaseError
impl Unpin for BaseError
impl UnsafeUnpin for BaseError
impl UnwindSafe for BaseError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.