From adaf55561675faaa1cd7b3f2109de10372514afc Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 12 Apr 2024 12:52:02 +0200 Subject: [PATCH] Handle errors --- packages/client/src/utils/buttonActions.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/client/src/utils/buttonActions.js b/packages/client/src/utils/buttonActions.js index da4dee9655..d883ee1b55 100644 --- a/packages/client/src/utils/buttonActions.js +++ b/packages/client/src/utils/buttonActions.js @@ -402,6 +402,7 @@ const closeSidePanelHandler = () => { } const downloadFileHandler = async action => { + const { url, fileName } = action.parameters try { const { type } = action.parameters if (type === "attachment") { @@ -416,12 +417,13 @@ const downloadFileHandler = async action => { return } - const { url, fileName } = action.parameters - const response = await fetch(url) if (!response.ok) { - throw `Url is not valid: ${url}` + notificationStore.actions.error( + `Failed to download from '${url}'. Server returned status code: ${response.status}` + ) + return } const objectUrl = URL.createObjectURL(await response.blob()) @@ -434,10 +436,12 @@ const downloadFileHandler = async action => { URL.revokeObjectURL(objectUrl) } catch (e) { console.error(e) - if (e.status === 404) { - notificationStore.actions.error("File is empty") + if (e.status) { + notificationStore.actions.error( + `Failed to download from '${url}'. Server returned status code: ${e.status}` + ) } else { - notificationStore.actions.error("File cannot be downloaded") + notificationStore.actions.error(`Failed to download from '${url}'.`) } } }