Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

错误码

envelope.code 编码

区间含义
0成功
1xxx客户端错误(参数 / 资源不存在 / 冲突)
2xxx上游错误(Cloudreve / 百度 4xx-5xx)
3xxx服务内部错误
Cloudreve 透传鉴权失败时直接透传 Cloudreve /user/infocode

完整映射表

HTTPenvelope.codeApiError 变体含义
2000成功
2001000BadRequest(msg)参数校验失败
2001004NotFound(msg)资源不存在
2001009Conflict(msg)唯一约束冲突(重名)
2002000Cli(CliError::Remote(...))上游远程错误(Cloudreve / 百度返非 0)
2002004Cli(CliError::NotFound(...))上游资源不存在(4xx 但归为“业务“)
2003002Cli(CliError::Config(...))配置错误(缺字段 / 非法值)
2003007Cli(CliError::Consistency(...))迁移一致性校验失败
4011000Unauthorized(msg)头缺失 / 格式错误 / JWT 过期
401透传UpstreamAuth { code, msg }Cloudreve 端 token 无效
4012001Cli(CliError::Auth(...))百度凭证过期 / 不存在
4031000Forbidden(msg)非 admin 访问 /admin/*
5003000Internal(msg)服务内部 panic / 未分类错误
5003001Cli(CliError::LocalIo(...))本地 IO 失败(写 db / log)

鉴权失败时 HTTP 401 + envelope.code 透传上游:客户端可以直接拿这个 code 跟 Cloudreve API 文档对照。其余业务错误一律 HTTP 200 + 业务 code 区分。

常见处理建议

code客户端应做
0处理 data
1000提示用户参数错误(看 msg
1004提示资源不存在;可能本地缓存过时,刷新列表
1009提示重名/冲突,让用户改名重试
2000 / 2001 / 2004上游故障,提示“暂时不可用“,按 msg 决定是否重试
3000 / 3001 / 3002server 端故障,无重试价值;上报 request_id 给管理员
3007一致性校验失败,提示用户检查源 / 目标差异;可调 migrate retry 重试
HTTP 401让用户重新登录 Cloudreve 拿新 token
HTTP 403非 admin 路径不要展示 admin 功能

last_err 字段

migrate_task 表有个 last_err 字段,记录最近一次失败的错误信息(人类可读字符串)。任务失败状态(failed / verify_failed)下通过 GET /migrate/jobs/{job_id}/tasksGET /admin/users/{user_id}/migrate 可以看到。