fix: add error handling and ui notifications for download failures (#217)
* fix: add error handling and ui notifications for download failures * fix: refactor error handling for download failures
This commit is contained in:
committed by
Bálint Ujvári
parent
7e05a56073
commit
b58f01cc2b
@@ -145,6 +145,12 @@ export function Share(): ReactElement {
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [hash])
|
}, [hash])
|
||||||
|
|
||||||
|
function downloadFailedWithError(err: unknown) {
|
||||||
|
const msg = <span>Error: {err instanceof Error ? err.message : String(err)}</span>
|
||||||
|
enqueueSnackbar(msg, { variant: 'error' })
|
||||||
|
setDownloading(false)
|
||||||
|
}
|
||||||
|
|
||||||
async function onDownload() {
|
async function onDownload() {
|
||||||
if (!beeApi || !hash) {
|
if (!beeApi || !hash) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
@@ -166,6 +172,7 @@ export function Share(): ReactElement {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error('Failed to download file: ', err)
|
console.error('Failed to download file: ', err)
|
||||||
|
downloadFailedWithError(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -184,6 +191,7 @@ export function Share(): ReactElement {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error('Failed to download files: ', err)
|
console.error('Failed to download files: ', err)
|
||||||
|
downloadFailedWithError(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -195,6 +203,7 @@ export function Share(): ReactElement {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.error('Failed to compress file: ', err)
|
console.error('Failed to compress file: ', err)
|
||||||
|
downloadFailedWithError(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user