Handle errors
This commit is contained in:
parent
c4c261ccbd
commit
adaf555616
|
@ -402,6 +402,7 @@ const closeSidePanelHandler = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const downloadFileHandler = async action => {
|
const downloadFileHandler = async action => {
|
||||||
|
const { url, fileName } = action.parameters
|
||||||
try {
|
try {
|
||||||
const { type } = action.parameters
|
const { type } = action.parameters
|
||||||
if (type === "attachment") {
|
if (type === "attachment") {
|
||||||
|
@ -416,12 +417,13 @@ const downloadFileHandler = async action => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { url, fileName } = action.parameters
|
|
||||||
|
|
||||||
const response = await fetch(url)
|
const response = await fetch(url)
|
||||||
|
|
||||||
if (!response.ok) {
|
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())
|
const objectUrl = URL.createObjectURL(await response.blob())
|
||||||
|
@ -434,10 +436,12 @@ const downloadFileHandler = async action => {
|
||||||
URL.revokeObjectURL(objectUrl)
|
URL.revokeObjectURL(objectUrl)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
if (e.status === 404) {
|
if (e.status) {
|
||||||
notificationStore.actions.error("File is empty")
|
notificationStore.actions.error(
|
||||||
|
`Failed to download from '${url}'. Server returned status code: ${e.status}`
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
notificationStore.actions.error("File cannot be downloaded")
|
notificationStore.actions.error(`Failed to download from '${url}'.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue