Improve error handling
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 1m40s
All checks were successful
Build on Push and create Release on Tag / build (push) Successful in 1m40s
This commit is contained in:
parent
05984a8913
commit
eaf4a8e39e
7 changed files with 109 additions and 45 deletions
|
@ -1,12 +1,80 @@
|
|||
import {showMessage} from "siyuan";
|
||||
|
||||
export class SyncIDNotFoundError extends Error {
|
||||
readonly fileID: string;
|
||||
export class InternationalizedError extends Error {
|
||||
readonly key: string;
|
||||
|
||||
constructor(fileID: string) {
|
||||
super(`SyncID not found for file ${fileID}`);
|
||||
this.fileID = fileID;
|
||||
Object.setPrototypeOf(this, new.target.prototype);
|
||||
constructor(key: string) {
|
||||
super(key);
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
export class UnchangedProtyleError extends Error {}
|
||||
export class ErrorReporter {
|
||||
|
||||
static i18n: any;
|
||||
|
||||
constructor(i18n: any) {
|
||||
ErrorReporter.i18n = i18n;
|
||||
}
|
||||
|
||||
static error(err: Error, timeout?: number) {
|
||||
console.error(err);
|
||||
let errorTxt = err.message;
|
||||
if(err instanceof InternationalizedError) {
|
||||
errorTxt = ErrorReporter.i18n[err.key];
|
||||
}
|
||||
if(!timeout) {
|
||||
timeout = 0;
|
||||
}
|
||||
showMessage(errorTxt, timeout, 'error');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class SyncIDNotFoundError extends InternationalizedError {
|
||||
constructor() {
|
||||
super('errSyncIDNotFound');
|
||||
}
|
||||
}
|
||||
|
||||
export class UnchangedProtyleError extends InternationalizedError {
|
||||
constructor() {
|
||||
super('errUnchangedProtyle');
|
||||
}
|
||||
}
|
||||
|
||||
export class MultipleSyncIDsError extends InternationalizedError {
|
||||
constructor() {
|
||||
super('errMultipleSyncIDs');
|
||||
}
|
||||
}
|
||||
|
||||
export class GenericSaveError extends InternationalizedError {
|
||||
constructor() {
|
||||
super('errSaveGeneric');
|
||||
}
|
||||
}
|
||||
|
||||
export class NotAWhiteboardError extends InternationalizedError {
|
||||
constructor() {
|
||||
super('errNotAWhiteboard');
|
||||
}
|
||||
}
|
||||
|
||||
export class InvalidBackgroundColorError extends InternationalizedError {
|
||||
constructor() {
|
||||
super('errInvalidBackgroundColor');
|
||||
}
|
||||
}
|
||||
|
||||
export class NoFileIDError extends InternationalizedError {
|
||||
constructor() {
|
||||
super('errNoFileID');
|
||||
}
|
||||
}
|
||||
|
||||
export class MustSelectError extends InternationalizedError {
|
||||
constructor() {
|
||||
super('errMustSelect');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue