From 87e4e3fe5ba328ea541dcec525bbaa78628c0d25 Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Mon, 22 Sep 2025 11:43:44 -0700 Subject: [PATCH] Catch all upload errors --- src/app/core/commands.ts | 58 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/app/core/commands.ts b/src/app/core/commands.ts index 9a870013..cc27aba7 100644 --- a/src/app/core/commands.ts +++ b/src/app/core/commands.ts @@ -680,35 +680,34 @@ export type UploadFileResult = { } export const uploadFile = async (file: File, options: UploadFileOptions = {}) => { - const {name, type} = file - - if (!type.match("image/(webp|gif)")) { - file = await compressFile(file) - } - - const tags: string[][] = [] - - if (options.encrypt) { - const {ciphertext, key, nonce, algorithm} = await encryptFile(file) - - tags.push( - ["decryption-key", key], - ["decryption-nonce", nonce], - ["encryption-algorithm", algorithm], - ) - - file = new File([new Blob([ciphertext])], name, { - type: "application/octet-stream", - }) - } - - const server = getBlossomServer() - const hashes = [await sha256(await file.arrayBuffer())] - const $signer = signer.get() || Nip01Signer.ephemeral() - const authTemplate = makeBlossomAuthEvent({action: "upload", server, hashes}) - const authEvent = await $signer.sign(authTemplate) - try { + const {name, type} = file + + if (!type.match("image/(webp|gif)")) { + file = await compressFile(file) + } + + const tags: string[][] = [] + + if (options.encrypt) { + const {ciphertext, key, nonce, algorithm} = await encryptFile(file) + + tags.push( + ["decryption-key", key], + ["decryption-nonce", nonce], + ["encryption-algorithm", algorithm], + ) + + file = new File([new Blob([ciphertext])], name, { + type: "application/octet-stream", + }) + } + + const server = getBlossomServer() + const hashes = [await sha256(await file.arrayBuffer())] + const $signer = signer.get() || Nip01Signer.ephemeral() + const authTemplate = makeBlossomAuthEvent({action: "upload", server, hashes}) + const authEvent = await $signer.sign(authTemplate) const res = await uploadBlob(server, file, {authEvent}) const text = await res.text() @@ -727,7 +726,8 @@ export const uploadFile = async (file: File, options: UploadFileOptions = {}) => return {result} } catch (e: any) { - console.error(e) + console.error("Error caught when uploading file:", e) + return {error: e.toString()} } }