jd-opensource/joyagent-jdgenie · error · Error
Network response was not ok
Error message
Network response was not ok
What it means
FileList's copy flow fetches fileItem.url and throws Error('Network response was not ok') on any non-2xx response, stopping the copy operation (stopCopying is called first). The user's copy-file action fails because the source file content could not be downloaded.
Solutions
- Refresh the file list to drop entries whose files no longer exist
- Catch the thrown error around the copy handler and show a user-facing message with retry
- Verify/refresh fileItem.url authorization before copying
- Check the file service logs for the failing status
- Add a HEAD pre-check on the URL before the full copy
Example fix
// before
const response = await fetch(fileItem.url);
if (!response.ok) {
stopCopying();
throw new Error('Network response was not ok');
}
// after
const response = await fetch(fileItem.url);
if (!response.ok) {
stopCopying();
message.error(`复制失败:文件下载返回 HTTP ${response.status}`);
return;
} Defensive patterns
Strategy: try-catch
Validate before calling
async function canCopy(url: string): Promise<boolean> {
try {
const res = await fetch(url, { method: 'HEAD' });
return res.ok;
} catch { return false; }
} Type guard
function isResponseOk(res: Response): boolean {
return res.ok && res.status >= 200 && res.status < 300;
} Try / catch
try {
await copyFile(fileItem);
} catch (e) {
stopCopying();
message.error(`复制失败:${(e as Error).message},请刷新文件列表后重试`);
} finally {
stopCopying();
} Prevention
- Always call stopCopying in a finally block so UI state recovers on failure
- Refresh the file list before copy operations on stale data
- Include response.status in the error message
- Re-request download URLs if a copy fails with 403
When it happens
Trigger: Clicking copy on a file whose URL returns 404/403/500; file removed from storage after the list was rendered; expired or revoked download link.
Common situations: Stale file list showing deleted entries; permission revoked mid-session; presigned URL expiry between listing and copying.
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/bba9ac879b9f92a5.
Report an issue: GitHub.
Appendix: source
Thrown at ui/src/components/ActionView/FileList.tsx:114
case 'csv':
case 'xlsx':
content = <TableRenderer fileUrl={fileItem.url} fileName={fileItem.name} />;
break;
default:
content = <FileRenderer fileUrl={fileItem.url} fileName={fileItem.name} />;
break;
}
}
const copy = useMemoizedFn(async () => {
if (!fileItem?.url) {
return;
}
startCopying();
const response = await fetch(fileItem.url);
if (!response.ok) {
stopCopying();
throw new Error('Network response was not ok');
}
const data = await response.text();
const copyData = data;
// const parts = fileItem.name?.split('.');
// const suffix = parts[parts.length - 1];
// this.activeFileContent = data
// const copyData = suffix === 'md' || suffix === 'txt' ? data : `\`\`\`${suffix}\n${data}\n\`\`\``;
// this.markDownContent = this.md.render(
// suffix === 'md' || suffix === 'txt'
// ? data
// : `\`\`\`${suffix}\n${data}\n\`\`\``
// )
copyText(copyData);
stopCopying();
showMessage()?.success('复制成功');
});View on GitHub (pinned to 2417e0b8b6)