Fix attachment preview retry and error catch

This commit is contained in:
windingwind 2024-01-19 11:18:49 +08:00 committed by Dan Stillman
parent 1c343ee820
commit 0cd7a52dc0
2 changed files with 6 additions and 2 deletions

View file

@ -50,6 +50,7 @@
this._isDiscardPlanned = false;
this._isDiscarding = false;
this._failedCount = 0;
this._intersectionOb = new IntersectionObserver(this._handleIntersection.bind(this));
this._resizeOb = new ResizeObserver(this._handleResize.bind(this));
@ -293,8 +294,10 @@
await this.discard(true);
this._reader = await Zotero.Reader.openPreview(this._item.id, this._id("preview"));
success = await this._reader._open({});
if (!success) {
// Retry 3 times if failed
if (!success && this._failedCount < 3) {
this._nextPreviewInitializePromise.resolve();
this._failedCount++;
// If failed on half-way of initialization, discard it
this.discard(true);
setTimeout(() => {
@ -306,6 +309,7 @@
else {
success = true;
}
if (success) this._failedCount = 0;
prev && (prev.disabled = true);
next && (next.disabled = false);
return success;

View file

@ -1347,7 +1347,7 @@ class ReaderPreview extends ReaderInstance {
return success;
}
catch (e) {
Zotero.warn(`Failed to load preview for attachment ${await this._item.getFilePathAsync()}: ${String(e)}`);
Zotero.warn(`Failed to load preview for attachment ${this._item?.libraryID}/${this._item?.key}: ${String(e)}`);
this._item = null;
return false;
}