From 2c639d7fe4391b0ad03f5b62a24e44c331d73919 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Mon, 9 Sep 2024 23:50:09 -0400 Subject: [PATCH] fix(web): show upload error message on network error (#12533) --- web/src/lib/utils/file-uploader.ts | 7 +++---- web/src/lib/utils/handle-error.ts | 10 ++++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/web/src/lib/utils/file-uploader.ts b/web/src/lib/utils/file-uploader.ts index d5b700fd6f..2e31605e91 100644 --- a/web/src/lib/utils/file-uploader.ts +++ b/web/src/lib/utils/file-uploader.ts @@ -15,7 +15,7 @@ import { import { tick } from 'svelte'; import { t } from 'svelte-i18n'; import { get } from 'svelte/store'; -import { getServerErrorMessage, handleError } from './handle-error'; +import { handleError } from './handle-error'; export const addDummyItems = () => { uploadAssetsStore.addItem({ id: 'asset-0', file: { name: 'asset0.jpg', size: 123_456 } as File }); @@ -202,10 +202,9 @@ async function fileUploader(assetFile: File, albumId?: string, replaceAssetId?: return responseData.id; } catch (error) { - handleError(error, $t('errors.unable_to_upload_file')); - const reason = getServerErrorMessage(error) || error; + const errorMessage = handleError(error, $t('errors.unable_to_upload_file')); uploadAssetsStore.track('error'); - uploadAssetsStore.updateItem(deviceAssetId, { state: UploadState.ERROR, error: reason }); + uploadAssetsStore.updateItem(deviceAssetId, { state: UploadState.ERROR, error: errorMessage }); return; } } diff --git a/web/src/lib/utils/handle-error.ts b/web/src/lib/utils/handle-error.ts index 6353a2049a..9ca5bc8773 100644 --- a/web/src/lib/utils/handle-error.ts +++ b/web/src/lib/utils/handle-error.ts @@ -20,11 +20,13 @@ export function handleError(error: unknown, message: string) { serverMessage = `${String(serverMessage).slice(0, 75)}\n(Immich Server Error)`; } - notificationController.show({ - message: serverMessage || message, - type: NotificationType.Error, - }); + const errorMessage = serverMessage || message; + + notificationController.show({ message: errorMessage, type: NotificationType.Error }); + + return errorMessage; } catch (error) { console.error(error); + return message; } }