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:
@@ -468,7 +468,9 @@ export async function apiRequest<T>(
|
||||
// 检查API返回的状态码
|
||||
const data = response.data;
|
||||
// 修复:支持code=0(PostgREST)和code=200(RBAC 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}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user