Notificaiton on error

This commit is contained in:
Adria Navarro 2024-03-25 18:13:56 +01:00
parent c1e78a099b
commit fb8163193c
1 changed files with 22 additions and 18 deletions

View File

@ -401,28 +401,32 @@ const closeSidePanelHandler = () => {
}
const downloadFileHandler = async (action, _context) => {
let { url, file_name, type, attachment } = action.parameters
if (type === "attachment") {
const attachmentObject = JSON.parse(attachment)
url = attachmentObject.url
file_name = attachmentObject.name
}
try {
let { url, file_name, type, attachment } = action.parameters
if (type === "attachment") {
const attachmentObject = JSON.parse(attachment)
url = attachmentObject.url
file_name = attachmentObject.name
}
const response = await fetch(url)
const response = await fetch(url)
if (!response.ok) {
if (!response.ok) {
throw `Url is not valid: ${url}`
}
const objectUrl = URL.createObjectURL(await response.blob())
const link = document.createElement("a")
link.href = objectUrl
link.download = file_name
link.click()
URL.revokeObjectURL(objectUrl)
} catch (e) {
console.error(e)
notificationStore.actions.error("File cannot be downloaded")
return
}
const objectUrl = URL.createObjectURL(await response.blob())
const link = document.createElement("a")
link.href = objectUrl
link.download = file_name
link.click()
URL.revokeObjectURL(objectUrl)
}
const handlerMap = {