diff --git a/frontend/src/components/FileExplorer.tsx b/frontend/src/components/FileExplorer.tsx index 8a36975..8dfa35d 100644 --- a/frontend/src/components/FileExplorer.tsx +++ b/frontend/src/components/FileExplorer.tsx @@ -647,14 +647,18 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) { async function executeDeleteSingle(file: FileItem) { const isPermanent = activeSection === 'trash'; - await api.deleteFile(file.path, isPermanent); - if (isPermanent) { - loadTrash(); - } else { - loadFiles(undefined, true); + try { + await api.deleteFile(file.path, isPermanent); + if (isPermanent) { + loadTrash(); + } else { + loadFiles(undefined, true); + } + setDeleteConfirm(null); + showToast(isPermanent ? `Permanently deleted ${file.name}` : `Deleted ${file.name}`); + } catch (err: any) { + showToast(`Delete failed: ${err.message}`); } - setDeleteConfirm(null); - showToast(isPermanent ? `Permanently deleted ${file.name}` : `Deleted ${file.name}`); } async function handlePin(file: FileItem) { diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index 962c093..300dea6 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -80,6 +80,14 @@ class ApiClient { } } + if (!response.ok && endpoint !== '/api/auth/refresh') { + let errorMsg = `HTTP ${response.status}`; + try { + const errData = await response.clone().json(); + if (errData.error) errorMsg = errData.error; + } catch {} + throw new Error(errorMsg); + } return response; } @@ -202,7 +210,7 @@ class ApiClient { } async deleteFile(path: string, permanent: boolean = false) { - const query = permanent ? '?permanent=true' : ''; + const query = permanent ? `?permanent=true&path=${encodeURIComponent(path)}` : `?path=${encodeURIComponent(path)}`; const res = await this.request(`/api/files/${encodeURIComponent(path)}${query}`, { method: 'DELETE', }); @@ -278,6 +286,7 @@ class ApiClient { // --- Pinned --- async listPinned() { const res = await this.request('/api/files/pinned'); + if (!res.ok) throw await res.json(); return res.json(); } @@ -286,16 +295,19 @@ class ApiClient { method: 'POST', body: { path }, }); + if (!res.ok) throw await res.json(); return res.json(); } async getTasks() { const res = await this.request('/api/tasks'); + if (!res.ok) throw await res.json(); return res.json(); } async getSettings() { const res = await this.request('/api/settings'); + if (!res.ok) throw await res.json(); return res.json(); }