fix: harden backup/restore error handling and security
- Stop analysis on WASM migration failure instead of continuing silently - Fail import when secrets exist but no encryption key is provided - Fail import on malformed secret values instead of skipping them - Tighten onboarding auth: missing onboarding row no longer grants access - Wrap WAL/SHM cleanup in try/catch so post-rename failure doesn't mask success - Show API errors immediately instead of waiting for animation to finish - Handle non-JSON server responses during restore (e.g. restart mid-request) - Surface fetchMigrations() failures as errors instead of empty array - Wrap migrations route I/O in try/catch with structured error response - Add server-side console.error logging to all backup API catch blocks - Fix export finally block: cleanup wrapped in try/catch to avoid masking - Fix misleading "Up to date" badge shown when migrations are pending - Remove dead PHASE_ICONS constant
This commit is contained in:
8 files changed
+88
-56
No files matched your search
@@ -55,14 +55,17 @@ export const DatabaseRestoreFlow = ({ variant = "card", onRestoreComplete }: Dat
|
||||
}, [reset]);
|
||||
|
||||
const tryFinalize = useCallback(() => {
|
||||
if (!apiDoneRef.current || !animDoneRef.current) return;
|
||||
if (!apiDoneRef.current) return;
|
||||
|
||||
if (apiErrorRef.current) {
|
||||
setImportError(apiErrorRef.current);
|
||||
setStep("error");
|
||||
} else {
|
||||
onRestoreComplete?.();
|
||||
window.location.reload();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!animDoneRef.current) return;
|
||||
onRestoreComplete?.();
|
||||
window.location.reload();
|
||||
}, [onRestoreComplete]);
|
||||
|
||||
const handleConfirm = useCallback(async () => {
|
||||
@@ -77,13 +80,17 @@ export const DatabaseRestoreFlow = ({ variant = "card", onRestoreComplete }: Dat
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
const response = await fetch("/api/backup/import", { method: "POST", body: formData });
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
apiErrorRef.current = data.error ?? t("analyzeError");
|
||||
try {
|
||||
const data = await response.json();
|
||||
apiErrorRef.current = data.error ?? t("failed.title");
|
||||
} catch {
|
||||
apiErrorRef.current = `Server returned ${response.status}`;
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
apiErrorRef.current = err instanceof Error ? err.message : t("analyzeError");
|
||||
} catch {
|
||||
apiErrorRef.current = t("failed.title");
|
||||
} finally {
|
||||
apiDoneRef.current = true;
|
||||
tryFinalize();
|
||||
|
||||
Reference in new issue
Block a user