Skip to main content

tdm_server_rust/common/
error_code.rs

1//! 错误码常量定义 (Error Codes)
2//!
3//! 对齐 Java `ErrorCode` 类,定义 HTTP 状态码与业务错误码。
4//! 所有常量通过 [`ErrorCode`] 结构体以关联常量的形式访问。
5
6/// HTTP 状态码与业务错误码常量集
7///
8/// ## 使用示例
9///
10/// ```rust
11/// use tdm_server_rust::common::ErrorCode;
12///
13/// assert_eq!(ErrorCode::SUCCESS, 200);
14/// assert_eq!(ErrorCode::LOGIN_REQUIRED, 401);
15/// ```
16///
17/// ## 取值说明
18///
19/// | 常量 | 值 | HTTP 对应 | 说明 |
20/// |------|-----|-----------|------|
21/// | `SUCCESS` | 200 | 200 OK | 操作成功 |
22/// | `SYSTEM_ERROR` | 500 | 500 Internal Server Error | 系统内部错误 |
23/// | `LOGIN_REQUIRED` | 401 | 401 Unauthorized | 未登录或 token 过期 |
24/// | `UNIQUE_VIOLATION` | 1002 | 409 Conflict | 数据库唯一约束冲突 |
25/// | `DOWNLOAD_UNAUTHENTIC` | 1003 | 403 Forbidden | 下载权限不足 |
26pub struct ErrorCode;
27
28impl ErrorCode {
29    /// 成功
30    pub const SUCCESS: i32 = 200;
31    /// 系统错误
32    pub const SYSTEM_ERROR: i32 = 500;
33    /// 需要登录
34    pub const LOGIN_REQUIRED: i32 = 401;
35    /// 唯一约束冲突
36    pub const UNIQUE_VIOLATION: i32 = 1002;
37    /// 下载无权限
38    pub const DOWNLOAD_UNAUTHENTIC: i32 = 1003;
39}