Skip to content

Commit fae88b3

Browse files
committed
ui: preserve download errors when aborting
1 parent 0d6aa77 commit fae88b3

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

  • packages/ui-default/components/zipDownloader

packages/ui-default/components/zipDownloader/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ export default async function download(filename, targets) {
3030
const fileStream = streamsaver.createWriteStream(filename);
3131
const queue = new PQueue({ concurrency: 5 });
3232
const abortCallbackReceiver: any = {};
33-
function stopDownload() { abortCallbackReceiver.abort?.(); }
33+
function stopDownload(reason?: unknown) {
34+
abortCallbackReceiver.abort?.(reason instanceof Error ? reason : new Error('Download aborted'));
35+
}
3436
let i = 0;
3537
async function downloadFile(target, retry = 5) {
3638
try {
3739
let stream;
3840
if (target.url) {
3941
const response = await fetch(target.url);
40-
if (!response.ok) throw response.statusText;
42+
if (!response.ok) throw new Error(`${response.status} ${response.statusText}`);
4143
stream = response.body;
4244
} else {
4345
stream = new Blob([target.content]).stream();
@@ -48,15 +50,14 @@ export default async function download(filename, targets) {
4850
};
4951
} catch (e) {
5052
if (retry) {
51-
Notification.warn(i18n('Download Error: {0} {1}, retry in 3 secs...', [target.filename, e.toString()]));
53+
Notification.warn(i18n('Download Error: {0} {1}, retry in 3 secs...', [target.filename, String(e)]));
5254
await sleep(3000);
5355
return await downloadFile(target, retry - 1);
5456
}
55-
window.captureException?.(e);
56-
stopDownload();
57-
Notification.error(i18n('Download Error: {0} {1}', [target.filename, e.toString()]));
57+
const error = new Error(i18n('Download Error: {0} {1}', [target.filename, String(e)]));
58+
stopDownload(error);
59+
throw error;
5860
}
59-
return {};
6061
}
6162
const handles = [];
6263
for (const target of targets) {

0 commit comments

Comments
 (0)