fix(axios-client): 修复 code 字段类型判断导致的误报错误

问题:
- axios-client 检查 API 响应中的 code 字段时,没有区分数字类型和字符串类型
- 当后端返回包含业务编码字段 code: "05PZSYTZSNRYZX" 的数据时,被误判为错误响应
- 导致 GET /api/v3/evaluation-points/:id 等接口报"API请求失败: 未知错误"

解决方案:
- 添加 typeof data.code === 'number' 类型检查
- 只有数字类型的 code 才被视为 API 状态码(0 或 200)
- 字符串类型的 code 被视为业务数据字段,不触发错误检查

影响范围:
- 所有返回包含字符串 code 字段的 API 响应
- 特别是评查点相关接口(code 是评查点编码)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-25 18:36:15 +08:00
parent 368b89fba0
commit 87a1bf87e5
+3 -1
View File
@@ -468,7 +468,9 @@ export async function apiRequest<T>(
// 检查API返回的状态码
const data = response.data;
// 修复:支持code=0PostgREST)和code=200RBAC API)两种成功响应
if (data && typeof data === 'object' && 'code' in data && data.code !== 0 && data.code !== 200) {
// 🔑 只有当 code 是数字类型时才认为是 API 状态码,字符串 code 是业务编码
if (data && typeof data === 'object' && 'code' in data &&
typeof data.code === 'number' && data.code !== 0 && data.code !== 200) {
const errorMessage = data.message || data.msg || '未知错误';
console.error(`API请求失败: ${errorMessage} - ${url}`);