From 06e8713fa55065d38f02499d3e8d39fc86926cab Mon Sep 17 00:00:00 2001 From: Ramires Viana <59319979+ramiresviana@users.noreply.github.com> Date: Fri, 1 Aug 2025 13:44:38 -0300 Subject: [PATCH] fix: show file upload errors --- frontend/src/api/tus.ts | 14 ++++++++++++-- frontend/src/components/Sidebar.vue | 9 ++------- frontend/src/views/Files.vue | 5 ++++- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/frontend/src/api/tus.ts b/frontend/src/api/tus.ts index fbfef4da..8bffa6a5 100644 --- a/frontend/src/api/tus.ts +++ b/frontend/src/api/tus.ts @@ -55,12 +55,22 @@ export async function upload( return true; }, - onError: function (error) { + onError: function (error: Error | tus.DetailedError) { if (CURRENT_UPLOAD_LIST[filePath].interval) { clearInterval(CURRENT_UPLOAD_LIST[filePath].interval); } delete CURRENT_UPLOAD_LIST[filePath]; - reject(new Error(`Upload failed: ${error.message}`)); + + const message = + error instanceof tus.DetailedError + ? error.originalResponse === null + ? "000 No connection" + : error.originalResponse.getBody() + : "Upload failed"; + + console.error(error); + + reject(new Error(message)); }, onProgress: function (bytesUploaded) { const fileData = CURRENT_UPLOAD_LIST[filePath]; diff --git a/frontend/src/components/Sidebar.vue b/frontend/src/components/Sidebar.vue index 74fb45ad..5bbf8847 100644 --- a/frontend/src/components/Sidebar.vue +++ b/frontend/src/components/Sidebar.vue @@ -132,7 +132,6 @@ import { import { files as api } from "@/api"; import ProgressBar from "@/components/ProgressBar.vue"; import prettyBytes from "pretty-bytes"; -import { StatusError } from "@/api/utils.js"; const USAGE_DEFAULT = { used: "0 B", total: "0 B", usedPercentage: 0 }; @@ -181,13 +180,9 @@ export default { total: prettyBytes(usage.total, { binary: true }), usedPercentage: Math.round((usage.used / usage.total) * 100), }; - } catch (error) { - if (error instanceof StatusError && error.is_canceled) { - return; - } - this.$showError(error); + } finally { + return Object.assign(this.usage, usageStats); } - return Object.assign(this.usage, usageStats); }, toRoot() { this.$router.push({ path: "/files" }); diff --git a/frontend/src/views/Files.vue b/frontend/src/views/Files.vue index 805f4027..950cb86d 100644 --- a/frontend/src/views/Files.vue +++ b/frontend/src/views/Files.vue @@ -26,6 +26,7 @@ import { computed, defineAsyncComponent, + inject, onBeforeUnmount, onMounted, onUnmounted, @@ -50,6 +51,8 @@ import { name } from "../utils/constants"; const Editor = defineAsyncComponent(() => import("@/views/files/Editor.vue")); const Preview = defineAsyncComponent(() => import("@/views/files/Preview.vue")); +const $showError = inject("$showError")!; + const layoutStore = useLayoutStore(); const fileStore = useFileStore(); const uploadStore = useUploadStore(); @@ -109,7 +112,7 @@ watch(reload, (newValue) => { newValue && fetchData(); }); watch(uploadError, (newValue) => { - newValue && layoutStore.showError(); + newValue && $showError(newValue); }); // Define functions