forge
Explore
Log in

Don't you dare go Hollow

🐛 notes file upload error handling and preview resilience

Browse files at this commit

f3306dd5333cedfbe0a713b8dc31f9b80ffbf044Burak BoduroğluParent: 5a4c1b9
  • fix
    • 🐛 notes file upload error handling and preview resilience
Show full message
fix: 🐛 notes file upload error handling and preview resilience
- blobClient parses JSON error body instead of bare status text
- NoteFilePreview shows fetch errors inline instead of hanging
- NoteFilesPanel removed 404/501 catch-all — backend file API live
- NotesPage reports partial file upload failures on create
- Added fileUploadPartial i18n keys (en/tr)
src/api/client.tsmodified+12 -1
@@ -209,7 +209,18 @@ export async function blobClient(path: string, signal?: AbortSignal): Promise<Bl
209 });209 });
210 210
211 if (!res.ok) {211 if (!res.ok) {
212- throw new ApiError(res.status, res.statusText || "Request failed");212+ const text = await res.text();
213+ let message = res.statusText || "Request failed";
214+ if (text) {
215+ try {
216+ const data = JSON.parse(text) as { error?: unknown; message?: unknown };
217+ if (typeof data.error === "string") message = data.error;
218+ else if (typeof data.message === "string") message = data.message;
219+ } catch {
220+ message = text;
221+ }
222+ }
223+ throw new ApiError(res.status, message);
213 }224 }
214 225
215 return res.blob();226 return res.blob();
src/components/notes/note-file-preview.tsxmodified+27 -18
@@ -1,4 +1,5 @@
1 import { Show, createEffect, createSignal, onCleanup } from "solid-js";1 import { Show, createEffect, createSignal, onCleanup } from "solid-js";
2+import { formatApiError } from "@/api/client";
2 import { getNoteFileBlob } from "@/api/getNoteFileBlob";3 import { getNoteFileBlob } from "@/api/getNoteFileBlob";
3 import type { NoteFile } from "@/api/types";4 import type { NoteFile } from "@/api/types";
4 import { getNoteFileUrl } from "@/api/getNoteFileUrl";5 import { getNoteFileUrl } from "@/api/getNoteFileUrl";
@@ -18,6 +19,7 @@ export function NoteFilePreview(props: { noteId: string; file: NoteFile | null;
18 const t = useT();19 const t = useT();
19 let currentUrl = "";20 let currentUrl = "";
20 const [previewUrl, setPreviewUrl] = createSignal("");21 const [previewUrl, setPreviewUrl] = createSignal("");
22+ const [previewError, setPreviewError] = createSignal("");
21 const downloadUrl = () => (props.file ? getNoteFileUrl(props.noteId, props.file.id) : "");23 const downloadUrl = () => (props.file ? getNoteFileUrl(props.noteId, props.file.id) : "");
22 const type = () => props.file?.content_type ?? "";24 const type = () => props.file?.content_type ?? "";
23 25
@@ -25,16 +27,21 @@ export function NoteFilePreview(props: { noteId: string; file: NoteFile | null;
25 if (currentUrl) URL.revokeObjectURL(currentUrl);27 if (currentUrl) URL.revokeObjectURL(currentUrl);
26 currentUrl = "";28 currentUrl = "";
27 setPreviewUrl("");29 setPreviewUrl("");
30+ setPreviewError("");
28 31
29 const file = props.file;32 const file = props.file;
30 if (!file || !canPreview(file)) return;33 if (!file || !canPreview(file)) return;
31 34
32 const controller = new AbortController();35 const controller = new AbortController();
33- void getNoteFileBlob(props.noteId, file.id, controller.signal).then((blob) => {36+ void getNoteFileBlob(props.noteId, file.id, controller.signal)
34- if (controller.signal.aborted) return;37+ .then((blob) => {
35- currentUrl = URL.createObjectURL(blob);38+ if (controller.signal.aborted) return;
36- setPreviewUrl(currentUrl);39+ currentUrl = URL.createObjectURL(blob);
37- });40+ setPreviewUrl(currentUrl);
41+ })
42+ .catch((err) => {
43+ if (!controller.signal.aborted) setPreviewError(formatApiError(err));
44+ });
38 45
39 onCleanup(() => {46 onCleanup(() => {
40 controller.abort();47 controller.abort();
@@ -69,19 +76,21 @@ export function NoteFilePreview(props: { noteId: string; file: NoteFile | null;
69 when={canPreview(file())}76 when={canPreview(file())}
70 fallback={<p class="mx-auto max-w-md rounded-md border border-dashed border-white/20 bg-white/5 px-4 py-8 text-center text-sm text-white/70">{t("notes.previewUnsupported")}</p>}77 fallback={<p class="mx-auto max-w-md rounded-md border border-dashed border-white/20 bg-white/5 px-4 py-8 text-center text-sm text-white/70">{t("notes.previewUnsupported")}</p>}
71 >78 >
72- <Show when={type().startsWith("image/") && previewUrl()} fallback={<p class="text-sm text-white/60">{t("common.loading")}</p>}>79+ <Show when={!previewError()} fallback={<p class="mx-auto max-w-md rounded-md border border-dashed border-white/20 bg-white/5 px-4 py-8 text-center text-sm text-white/70">{previewError()}</p>}>
73- <img src={previewUrl()} alt={file().name} class="max-h-full max-w-full object-contain" />80+ <Show when={type().startsWith("image/") && previewUrl()} fallback={<p class="text-sm text-white/60">{t("common.loading")}</p>}>
74- </Show>81+ <img src={previewUrl()} alt={file().name} class="max-h-full max-w-full object-contain" />
75- <Show when={type().startsWith("video/") && previewUrl()}>82+ </Show>
76- <video src={previewUrl()} controls class="max-h-full max-w-full" />83+ <Show when={type().startsWith("video/") && previewUrl()}>
77- </Show>84+ <video src={previewUrl()} controls class="max-h-full max-w-full" />
78- <Show when={type().startsWith("audio/") && previewUrl()}>85+ </Show>
79- <div class="w-full max-w-2xl rounded-lg bg-background p-4 shadow-sm">86+ <Show when={type().startsWith("audio/") && previewUrl()}>
80- <audio src={previewUrl()} controls class="w-full" />87+ <div class="w-full max-w-2xl rounded-lg bg-background p-4 shadow-sm">
81- </div>88+ <audio src={previewUrl()} controls class="w-full" />
82- </Show>89+ </div>
83- <Show when={canFrame(type()) && previewUrl()}>90+ </Show>
84- <iframe title={file().name} src={previewUrl()} class="h-full w-full rounded-md border border-white/10 bg-background" />91+ <Show when={canFrame(type()) && previewUrl()}>
92+ <iframe title={file().name} src={previewUrl()} class="h-full w-full rounded-md border border-white/10 bg-background" />
93+ </Show>
85 </Show>94 </Show>
86 </Show>95 </Show>
87 </div>96 </div>
src/components/notes/note-files-panel.tsxmodified+2 -8
@@ -4,7 +4,7 @@ import { getNoteFileUrl } from "@/api/getNoteFileUrl";
4 import { getNoteFiles } from "@/api/getNoteFiles";4 import { getNoteFiles } from "@/api/getNoteFiles";
5 import { getSettings } from "@/api/getSettings";5 import { getSettings } from "@/api/getSettings";
6 import { postNoteFile } from "@/api/postNoteFile";6 import { postNoteFile } from "@/api/postNoteFile";
7-import { ApiError, formatApiError } from "@/api/client";7+import { formatApiError } from "@/api/client";
8 import type { NoteFile } from "@/api/types";8 import type { NoteFile } from "@/api/types";
9 import { NoteFilePreview } from "@/components/notes/note-file-preview";9 import { NoteFilePreview } from "@/components/notes/note-file-preview";
10 import { Button } from "@/components/ui/button";10 import { Button } from "@/components/ui/button";
@@ -65,13 +65,7 @@ export function NoteFilesPanel(props: { noteId: string; active: boolean }) {
65 () => (props.active ? props.noteId : null),65 () => (props.active ? props.noteId : null),
66 async (noteId) => {66 async (noteId) => {
67 if (!noteId) return [] as NoteFile[];67 if (!noteId) return [] as NoteFile[];
68- // ponytail: empty on 404 so missing BE file API doesn't kill the reader dialog68+ return (await getNoteFiles(noteId, { limit: MAX_NOTE_FILES })).items;
69- try {
70- return (await getNoteFiles(noteId, { limit: MAX_NOTE_FILES })).items;
71- } catch (err) {
72- if (err instanceof ApiError && (err.status === 404 || err.status === 501)) return [];
73- throw err;
74- }
75 },69 },
76 );70 );
77 const [settings] = createResource(async () => {71 const [settings] = createResource(async () => {
src/i18n/messages.tsmodified+3 -0
@@ -184,6 +184,7 @@ export type MessageKey =
184 | "notes.noFiles"184 | "notes.noFiles"
185 | "notes.fileLimit"185 | "notes.fileLimit"
186 | "notes.fileTooLarge"186 | "notes.fileTooLarge"
187+ | "notes.fileUploadPartial"
187 | "notes.previewUnsupported"188 | "notes.previewUnsupported"
188 | "notes.unknownFileType"189 | "notes.unknownFileType"
189 | "notes.helpTitle"190 | "notes.helpTitle"
@@ -710,6 +711,7 @@ const en: Dict = {
710 "notes.noFiles": "No files attached.",711 "notes.noFiles": "No files attached.",
711 "notes.fileLimit": "This note already has 10 files.",712 "notes.fileLimit": "This note already has 10 files.",
712 "notes.fileTooLarge": "File is too large. Max {size}.",713 "notes.fileTooLarge": "File is too large. Max {size}.",
714+ "notes.fileUploadPartial": "Note saved, but {count} file(s) could not be uploaded.",
713 "notes.previewUnsupported": "Preview is not available for this file type. Download the file to open it.",715 "notes.previewUnsupported": "Preview is not available for this file type. Download the file to open it.",
714 "notes.unknownFileType": "Unknown file type",716 "notes.unknownFileType": "Unknown file type",
715 "notes.helpTitle": "About notes",717 "notes.helpTitle": "About notes",
@@ -1248,6 +1250,7 @@ const tr: Dict = {
1248 "notes.noFiles": "Henüz dosya eklenmemiş.",1250 "notes.noFiles": "Henüz dosya eklenmemiş.",
1249 "notes.fileLimit": "Bu notta zaten 10 dosya var.",1251 "notes.fileLimit": "Bu notta zaten 10 dosya var.",
1250 "notes.fileTooLarge": "Dosya çok büyük. En fazla {size}.",1252 "notes.fileTooLarge": "Dosya çok büyük. En fazla {size}.",
1253+ "notes.fileUploadPartial": "Not kaydedildi ama {count} dosya yüklenemedi.",
1251 "notes.previewUnsupported": "Bu dosya türü için önizleme yok. Açmak için dosyayı indirin.",1254 "notes.previewUnsupported": "Bu dosya türü için önizleme yok. Açmak için dosyayı indirin.",
1252 "notes.unknownFileType": "Bilinmeyen dosya türü",1255 "notes.unknownFileType": "Bilinmeyen dosya türü",
1253 "notes.helpTitle": "Notlar hakkında",1256 "notes.helpTitle": "Notlar hakkında",
src/pages/notes-page.tsxmodified+8 -2
@@ -86,16 +86,22 @@ function NotesContent() {
86 submitLabel={t("common.create")}86 submitLabel={t("common.create")}
87 onCancel={() => setCreateOpen(false)}87 onCancel={() => setCreateOpen(false)}
88 onSubmit={async (values) => {88 onSubmit={async (values) => {
89+ setError("");
89 const note = await postNote({90 const note = await postNote({
90 title: values.title,91 title: values.title,
91 content: values.content || undefined,92 content: values.content || undefined,
92 });93 });
93- // ponytail: upload after create — file API needs note id94+ let failedUploads = 0;
94 for (const file of values.files) {95 for (const file of values.files) {
95- await postNoteFile(note.id, file);96+ try {
97+ await postNoteFile(note.id, file);
98+ } catch {
99+ failedUploads += 1;
100+ }
96 }101 }
97 await refetch();102 await refetch();
98 setCreateOpen(false);103 setCreateOpen(false);
104+ if (failedUploads > 0) setError(t("notes.fileUploadPartial", { count: failedUploads }));
99 }}105 }}
100 />106 />
101 </SidePanel>107 </SidePanel>