fix(studio): make optional file reads explicit (#883)

This commit is contained in:
Phuong Le
2026-05-16 04:42:56 +02:00
committed by GitHub
parent 4b501762e4
commit 395cbaf3f5
3 changed files with 82 additions and 4 deletions
+3 -2
View File
@@ -108,8 +108,9 @@ export function useFileManager({
const readOptionalProjectFile = useCallback(async (path: string): Promise<string> => {
const pid = projectIdRef.current;
if (!pid) throw new Error("No active project");
const response = await fetch(`/api/projects/${pid}/files/${encodeURIComponent(path)}`);
if (response.status === 404) return "";
const response = await fetch(
`/api/projects/${pid}/files/${encodeURIComponent(path)}?optional=1`,
);
if (!response.ok) throw new Error(`Failed to read ${path}`);
const data = (await response.json()) as { content?: string };
return typeof data.content === "string" ? data.content : "";