Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: mark att. as failed on error

thecodrr9d097b11cbbb
diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.js
index 1ae7ad88c..6a3e851c5 100644
--- a/packages/core/api/sync/index.js
+++ b/packages/core/api/sync/index.js
@@ -186,7 +186,7 @@ export default class Sync {
const attachments = this._db.attachments.pending;
for (var i = 0; i < attachments.length; ++i) {
const attachment = attachments[i];
- const { hash, filename } = attachment.metadata;
+ const { hash } = attachment.metadata;
sendAttachmentsProgressEvent("upload", hash, attachments.length, i);
try {
@@ -195,9 +195,9 @@ export default class Sync {
await this._db.attachments.markAsUploaded(attachment.id);
} catch (e) {
- throw new Error(
- `Failed to upload the following attachment: "${filename}". Please try attaching this file again. (Reference error: ${e.message})`
- );
+ console.error(e, attachment);
+ const error = e.message;
+ await this._db.attachments.markAsFailed(attachment.id, error);
}
}
sendAttachmentsProgressEvent("upload", null, attachments.length);
diff --git a/packages/core/collections/attachments.js b/packages/core/collections/attachments.js
index 2e526eaae..0f30c1808 100644
--- a/packages/core/collections/attachments.js
+++ b/packages/core/collections/attachments.js
@@ -114,6 +114,7 @@ export default class Attachments extends Collection {
dateModified: undefined,
dateUploaded: undefined,
dateDeleted: undefined,
+ failed: attachment.failed,
};
return this._collection.addItem(attachmentItem);
}
@@ -219,9 +220,16 @@ export default class Attachments extends Collection {
}
markAsUploaded(id) {
- const attachment = this.all.find((a) => a.id === id);
+ const attachment = this.attachment(id);
if (!attachment) return;
attachment.dateUploaded = Date.now();
+ attachment.failed = undefined;
+ return this._collection.updateItem(attachment);
+ }
+ markAsFailed(id, reason) {
+ const attachment = this.attachment(id);
+ if (!attachment) return;
+ attachment.failed = reason || true;
return this._collection.updateItem(attachment);
}