From f5b1e913781b759cb13d7f4c242814aaa55ffd6b Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 23 Mar 2026 14:34:45 -0700 Subject: [PATCH] Handle json parsing errors on file upload --- src/app/core/commands.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/app/core/commands.ts b/src/app/core/commands.ts index 2c028336..cda0414a 100644 --- a/src/app/core/commands.ts +++ b/src/app/core/commands.ts @@ -642,13 +642,19 @@ export const uploadFile = async (file: File, options: UploadFileOptions = {}) => const res = await uploadBlob(server, file, {authEvent}) const text = await res.text() - let {uploaded, url, ...task} = parseJson(text) || {} + let task + try { + task = parseJson(text) + } catch (e) { + return {error: text} + } - if (!uploaded) { + if (!task?.uploaded) { return {error: text || `Failed to upload file (HTTP ${res.status})`} } // Always append correct file extension if we encrypted the file, or if it's missing + let url = task.url if (options.encrypt) { url = url.replace(/\.\w+$/, "") + ext } else if (new URL(url).pathname.split(".").length === 1) {