add error notices to plugin

This commit is contained in:
Maxime Cannoodt 2022-06-29 22:24:59 +02:00
parent 91f6205b90
commit 4c7479a8a9
3 changed files with 24 additions and 4 deletions

View File

@ -1,4 +1,11 @@
import { MarkdownView, Menu, Plugin, TAbstractFile, TFile } from "obsidian";
import {
MarkdownView,
Menu,
Notice,
Plugin,
TAbstractFile,
TFile,
} from "obsidian";
import { NoteSharingService } from "src/NoteSharingService";
import { DEFAULT_SETTINGS } from "src/obsidian/PluginSettings";
import SettingsTab from "src/obsidian/SettingsTab";
@ -76,7 +83,18 @@ export default class NoteSharingPlugin extends Plugin {
}
async shareNote(mdText: string) {
const res = await this.noteSharingService.shareNote(mdText);
new SharedNoteSuccessModal(this, res.view_url, res.expire_time).open();
this.noteSharingService
.shareNote(mdText)
.then((res) => {
new SharedNoteSuccessModal(
this,
res.view_url,
res.expire_time
).open();
})
.catch((err: Error) => {
console.error(err);
new Notice(err.message, 7500);
});
}
}

View File

@ -43,7 +43,9 @@ export class NoteSharingService {
returnValue.expire_time = moment(returnValue.expire_time);
return <Response>returnValue;
}
throw Error("Did not get expected response from server on note POST.");
throw Error(
`Error uploading encrypted note (${res.status}): ${res.text}`
);
}
private sanitizeNote(mdText: string): string {

Binary file not shown.