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
209209 });
210210
211211 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);
213224 }
214225
215226 return res.blob();
src/components/notes/note-file-preview.tsxmodified+27 -18
@@ -1,4 +1,5 @@
11 import { Show, createEffect, createSignal, onCleanup } from "solid-js";
2+import { formatApiError } from "@/api/client";
23 import { getNoteFileBlob } from "@/api/getNoteFileBlob";
34 import type { NoteFile } from "@/api/types";
45 import { getNoteFileUrl } from "@/api/getNoteFileUrl";
@@ -18,6 +19,7 @@ export function NoteFilePreview(props: { noteId: string; file: NoteFile | null;
1819 const t = useT();
1920 let currentUrl = "";
2021 const [previewUrl, setPreviewUrl] = createSignal("");
22+ const [previewError, setPreviewError] = createSignal("");
2123 const downloadUrl = () => (props.file ? getNoteFileUrl(props.noteId, props.file.id) : "");
2224 const type = () => props.file?.content_type ?? "";
2325
@@ -25,16 +27,21 @@ export function NoteFilePreview(props: { noteId: string; file: NoteFile | null;
2527 if (currentUrl) URL.revokeObjectURL(currentUrl);
2628 currentUrl = "";
2729 setPreviewUrl("");
30+ setPreviewError("");
2831
2932 const file = props.file;
3033 if (!file || !canPreview(file)) return;
3134
3235 const controller = new AbortController();
33- void getNoteFileBlob(props.noteId, file.id, controller.signal).then((blob) => {
34- if (controller.signal.aborted) return;
35- currentUrl = URL.createObjectURL(blob);
36- setPreviewUrl(currentUrl);
37- });
36+ void getNoteFileBlob(props.noteId, file.id, controller.signal)
37+ .then((blob) => {
38+ if (controller.signal.aborted) return;
39+ currentUrl = URL.createObjectURL(blob);
40+ setPreviewUrl(currentUrl);
41+ })
42+ .catch((err) => {
43+ if (!controller.signal.aborted) setPreviewError(formatApiError(err));
44+ });
3845
3946 onCleanup(() => {
4047 controller.abort();
@@ -69,19 +76,21 @@ export function NoteFilePreview(props: { noteId: string; file: NoteFile | null;
6976 when={canPreview(file())}
7077 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>}
7178 >
72- <Show when={type().startsWith("image/") && previewUrl()} fallback={<p class="text-sm text-white/60">{t("common.loading")}</p>}>
73- <img src={previewUrl()} alt={file().name} class="max-h-full max-w-full object-contain" />
74- </Show>
75- <Show when={type().startsWith("video/") && previewUrl()}>
76- <video src={previewUrl()} controls class="max-h-full max-w-full" />
77- </Show>
78- <Show when={type().startsWith("audio/") && previewUrl()}>
79- <div class="w-full max-w-2xl rounded-lg bg-background p-4 shadow-sm">
80- <audio src={previewUrl()} controls class="w-full" />
81- </div>
82- </Show>
83- <Show when={canFrame(type()) && previewUrl()}>
84- <iframe title={file().name} src={previewUrl()} class="h-full w-full rounded-md border border-white/10 bg-background" />
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>}>
80+ <Show when={type().startsWith("image/") && previewUrl()} fallback={<p class="text-sm text-white/60">{t("common.loading")}</p>}>
81+ <img src={previewUrl()} alt={file().name} class="max-h-full max-w-full object-contain" />
82+ </Show>
83+ <Show when={type().startsWith("video/") && previewUrl()}>
84+ <video src={previewUrl()} controls class="max-h-full max-w-full" />
85+ </Show>
86+ <Show when={type().startsWith("audio/") && previewUrl()}>
87+ <div class="w-full max-w-2xl rounded-lg bg-background p-4 shadow-sm">
88+ <audio src={previewUrl()} controls class="w-full" />
89+ </div>
90+ </Show>
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>
8594 </Show>
8695 </Show>
8796 </div>
src/components/notes/note-files-panel.tsxmodified+2 -8
@@ -4,7 +4,7 @@ import { getNoteFileUrl } from "@/api/getNoteFileUrl";
44 import { getNoteFiles } from "@/api/getNoteFiles";
55 import { getSettings } from "@/api/getSettings";
66 import { postNoteFile } from "@/api/postNoteFile";
7-import { ApiError, formatApiError } from "@/api/client";
7+import { formatApiError } from "@/api/client";
88 import type { NoteFile } from "@/api/types";
99 import { NoteFilePreview } from "@/components/notes/note-file-preview";
1010 import { Button } from "@/components/ui/button";
@@ -65,13 +65,7 @@ export function NoteFilesPanel(props: { noteId: string; active: boolean }) {
6565 () => (props.active ? props.noteId : null),
6666 async (noteId) => {
6767 if (!noteId) return [] as NoteFile[];
68- // ponytail: empty on 404 so missing BE file API doesn't kill the reader dialog
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- }
68+ return (await getNoteFiles(noteId, { limit: MAX_NOTE_FILES })).items;
7569 },
7670 );
7771 const [settings] = createResource(async () => {
src/i18n/messages.tsmodified+3 -0
@@ -184,6 +184,7 @@ export type MessageKey =
184184 | "notes.noFiles"
185185 | "notes.fileLimit"
186186 | "notes.fileTooLarge"
187+ | "notes.fileUploadPartial"
187188 | "notes.previewUnsupported"
188189 | "notes.unknownFileType"
189190 | "notes.helpTitle"
@@ -710,6 +711,7 @@ const en: Dict = {
710711 "notes.noFiles": "No files attached.",
711712 "notes.fileLimit": "This note already has 10 files.",
712713 "notes.fileTooLarge": "File is too large. Max {size}.",
714+ "notes.fileUploadPartial": "Note saved, but {count} file(s) could not be uploaded.",
713715 "notes.previewUnsupported": "Preview is not available for this file type. Download the file to open it.",
714716 "notes.unknownFileType": "Unknown file type",
715717 "notes.helpTitle": "About notes",
@@ -1248,6 +1250,7 @@ const tr: Dict = {
12481250 "notes.noFiles": "Henüz dosya eklenmemiş.",
12491251 "notes.fileLimit": "Bu notta zaten 10 dosya var.",
12501252 "notes.fileTooLarge": "Dosya çok büyük. En fazla {size}.",
1253+ "notes.fileUploadPartial": "Not kaydedildi ama {count} dosya yüklenemedi.",
12511254 "notes.previewUnsupported": "Bu dosya türü için önizleme yok. Açmak için dosyayı indirin.",
12521255 "notes.unknownFileType": "Bilinmeyen dosya türü",
12531256 "notes.helpTitle": "Notlar hakkında",
src/pages/notes-page.tsxmodified+8 -2
@@ -86,16 +86,22 @@ function NotesContent() {
8686 submitLabel={t("common.create")}
8787 onCancel={() => setCreateOpen(false)}
8888 onSubmit={async (values) => {
89+ setError("");
8990 const note = await postNote({
9091 title: values.title,
9192 content: values.content || undefined,
9293 });
93- // ponytail: upload after create — file API needs note id
94+ let failedUploads = 0;
9495 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+ }
96101 }
97102 await refetch();
98103 setCreateOpen(false);
104+ if (failedUploads > 0) setError(t("notes.fileUploadPartial", { count: failedUploads }));
99105 }}
100106 />
101107 </SidePanel>