jd-opensource/joyagent-jdgenie · error · Error

网络错误

Error message

网络错误

What it means

TableRenderer fetches fileUrl and throws Error('网络错误') ('network error') when res.ok is false, i.e. any non-2xx HTTP status, before parsing the CSV/Excel content. The table cannot render without the file data.

Solutions

  1. Confirm fileUrl resolves (open it in a browser) and returns 200
  2. Regenerate or refresh the file download URL
  3. Render the `error` state from useRequest with a retry action
  4. Check that the file type/mode matches the actual file (excel vs csv handling)
  5. Inspect the storage service for why the object is unavailable

Example fix

// before
const res = await fetch(fileUrl);
if (!res.ok) throw new Error('网络错误');
// after
const res = await fetch(fileUrl);
if (!res.ok) {
  throw new Error(`表格加载失败 (HTTP ${res.status})`);
}
return fileType === 'excel' ? res.arrayBuffer() : res.text();
Defensive patterns

Strategy: try-catch

Validate before calling

async function assertTableAvailable(url: string): Promise<boolean> {
  try {
    const res = await fetch(url, { method: 'HEAD' });
    return res.ok;
  } catch { return false; }
}

Type guard

function isOk(res: Response): res is Response & { ok: true } {
  return res.ok;
}

Try / catch

const { data, error, run } = useRequest(() => loadTable(fileUrl, fileType), {
  refreshDeps: [fileUrl],
  onError: (e) => message.error(`表格加载失败:${e.message}`),
});
if (error) return <Button onClick={run}>重新加载</Button>;

Prevention

When it happens

Trigger: The spreadsheet URL returns 404 (file missing), 403 (expired link or denied access), or 5xx server error; a wrong fileUrl passed via props.

Common situations: Excel/CSV exported files deleted by cleanup jobs; presigned URL expiry; permission changes on the storage bucket; misconfigured base path in fileUrl.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of jd-opensource/joyagent-jdgenie@2417e0b8b6 (2026-09-08). Data as JSON: /api/errors/3098d8b178db93aa. Report an issue: GitHub.

Appendix: source

Thrown at ui/src/components/ActionPanel/TableRenderer.tsx:35

  /**
   * 文件类型,默认为文件扩展名决定
   */
  mode?: 'csv' | 'excel';
  /**
   * 文件名
   */
  fileName?: string;
}> = (props) => {
  const { fileUrl, mode, fileName } = props;

  const ext = (fileName || fileUrl).split('.').pop()?.toLowerCase();

  const fileType = mode || (ext === 'xlsx' || ext === 'xlsm' || ext === 'xlsb' || ext === 'xls' ? 'excel' : 'csv');

  // 拉取 CSV 文本
  const { data, loading, error } = useRequest(async () => {
    const res = await fetch(fileUrl);
    if (!res.ok) throw new Error('网络错误');

    if (fileType === 'excel') {
      return res.arrayBuffer();
    }

    return res.text();
  },
  { refreshDeps: [fileUrl] }
  );

  // 解析 CSV
  const { columns, dataSource, parseError } = useMemo(() => {
    if (!data) return {
      columns: [],
      dataSource: [],
      parseError: false
    };

View on GitHub (pinned to 2417e0b8b6)