mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-17 05:58:37 +00:00
fix: surface NOT_EMPTY error code so DeleteFileConfirm can offer recursive delete (#1765)
* fix: surface NOT_EMPTY error code so DeleteFileConfirm can offer recursive retry The parseApiError helper discards the backend's machine-readable code field, returning only the human-readable message. DeleteFileConfirm tried to detect non-empty directory refusals by matching the substring NOT_EMPTY against the message text, but the actual server message is "Directory is not empty" (with spaces, not underscores), so the two-step "Delete all" confirmation flow was dead code. Add a NotEmptyError class (mirroring the existing UploadConflictError pattern) and intercept HTTP 409 responses in deleteStackPath so the code is preserved. Replace the fragile string match in DeleteFileConfirm with instanceof. * fix: extend NOT_EMPTY fix to volume roots and fix stale viewer after recursive delete P0-1: sendFsError's helper/ExecError branch (volume-browser deletes) never attached a code field to 409 responses, so the frontend NotEmptyError was never thrown for named-volume non-empty directories. Map ExecError 409s whose message matches 'not empty' to code: NOT_EMPTY. P0-2: The context-menu delete onDeleted callback used an exact-match check (ctxDeletePath === selectedPath) to decide whether to clear the viewer. When deleting a folder containing the open file, the viewer stayed open showing now-deleted content. Use the existing openFileAffectedBy helper (which checks ancestor paths) instead, matching bulk-delete behavior.
This commit is contained in:
@@ -380,6 +380,20 @@ export async function writeStackFile(
|
||||
return { version, mtimeMs };
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown by deleteStackPath when the server refuses to delete a non-empty
|
||||
* directory without the recursive flag (HTTP 409, code NOT_EMPTY). The
|
||||
* DeleteFileConfirm dialog promotes its confirm button to "Delete all" on
|
||||
* this signal and retries with recursive=true.
|
||||
*/
|
||||
export class NotEmptyError extends Error {
|
||||
readonly code = 'NOT_EMPTY' as const;
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'NotEmptyError';
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteStackPath(
|
||||
stackName: string,
|
||||
relPath: string,
|
||||
@@ -392,6 +406,15 @@ export async function deleteStackPath(
|
||||
stackFilesUrl(stackName, `?path=${encodeURIComponent(relPath)}${recursiveSuffix}${rootParam(rootId)}`),
|
||||
{ method: 'DELETE' },
|
||||
);
|
||||
if (res.status === 409) {
|
||||
let body: { code?: string; error?: string } = {};
|
||||
try { body = await res.clone().json(); } catch { /* ignore */ }
|
||||
if (body.code === 'NOT_EMPTY') {
|
||||
throw new NotEmptyError(body.error ?? 'Directory is not empty.');
|
||||
}
|
||||
// PROTECTED_FILE and any other 409 fall through to the generic Error path
|
||||
// so the caller surfaces the server message as a toast.
|
||||
}
|
||||
if (!res.ok) throw new Error(await parseApiError(res));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user