From e7f4d8c9c2a278452d4b24aaaa082202ea2f0eb6 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Mon, 29 Aug 2022 16:13:54 +0900 Subject: [PATCH] Add error handling for loading the document --- src/DocumentHistoryModal.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/DocumentHistoryModal.ts b/src/DocumentHistoryModal.ts index 2e34246..9d48966 100644 --- a/src/DocumentHistoryModal.ts +++ b/src/DocumentHistoryModal.ts @@ -31,14 +31,25 @@ export class DocumentHistoryModal extends Modal { } async loadFile() { const db = this.plugin.localDatabase; - const w = await db.localDatabase.get(path2id(this.file), { revs_info: true }); - this.revs_info = w._revs_info.filter((e) => e.status == "available"); - this.range.max = `${this.revs_info.length - 1}`; - this.range.value = this.range.max; - this.fileInfo.setText(`${this.file} / ${this.revs_info.length} revisions`); - await this.loadRevs(); + try { + const w = await db.localDatabase.get(path2id(this.file), { revs_info: true }); + this.revs_info = w._revs_info.filter((e) => e.status == "available"); + this.range.max = `${this.revs_info.length - 1}`; + this.range.value = this.range.max; + this.fileInfo.setText(`${this.file} / ${this.revs_info.length} revisions`); + await this.loadRevs(); + } catch (ex) { + if (ex.status && ex.status == 404) { + this.range.max = "0"; + this.range.value = ""; + this.range.disabled = true; + this.showDiff + this.contentView.setText(`History of this file was not recorded.`); + } + } } async loadRevs() { + if (this.revs_info.length == 0) return; const db = this.plugin.localDatabase; const index = this.revs_info.length - 1 - (this.range.value as any) / 1; const rev = this.revs_info[index];