Skip to content

Commit

Permalink
fix: error handling of cancelled upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jarrvis committed Nov 17, 2023
1 parent 179547a commit 9d1160d
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/core/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,9 @@ class BatchService extends Service {
tags: service.arweaveTags,
item
}), { signal: options.cancelHook?.signal })
.catch((error) => {
if (error instanceof AbortError || options.cancelHook?.signal?.aborted) {
return ({ data, errors, cancelled: items.length - stacksCreated });
}
errors.push({ name: item.name || item.file.name, message: error.toString(), error });
});
} catch (error) {
if (!options.cancelHook?.signal?.aborted) {
errors.push({ name: item.name || item.file.name, message: error.toString(), error });
if (!(error instanceof AbortError) && !options.cancelHook?.signal?.aborted) {
errors.push({ name: item.name ,message: error.toString(), error });
}
}
}
Expand All @@ -220,12 +214,14 @@ class BatchService extends Service {
try {
await uploadQ.addAll(items.map(item => () => uploadItem(item)), { signal: options.cancelHook?.signal });
} catch (error) {
if (error instanceof AbortError || !options.cancelHook?.signal?.aborted) {
return ({ data, errors, cancelled: items.length - stacksCreated });
if (!(error instanceof AbortError) && !options.cancelHook?.signal?.aborted) {
errors.push({ message: error.toString(), error });
}
errors.push({ message: error.toString(), error });
}
await postTxQ.onIdle();
if (options.cancelHook?.signal?.aborted) {
return ({ data, errors, cancelled: items.length - stacksCreated });
}
return { data, errors, cancelled: 0 };
}

Expand Down

0 comments on commit 9d1160d

Please sign in to comment.