feat(fe/errors): add error log and prompt related pieces

This commit is contained in:
hexxa 2021-12-20 17:10:41 +08:00 committed by Hexxa
parent ba17416755
commit f0e898d1ae
3 changed files with 66 additions and 0 deletions

View file

@ -0,0 +1,5 @@
export const errUpdater = "err.updater";
export const errUploadMgr = "err.uploadMgr";
export const errServer = "err.server";
export const errCorsScript = "err.script.cors";
export const errUnknown = "err.unknown";

View file

@ -0,0 +1,46 @@
import { ILocalStorage, Storage } from "./localstorage";
import { ISettingsClient } from "../client";
import { SettingsClient } from "../client/settings";
export interface IErrorLogger {
setClient: (client: ISettingsClient) => void;
setStorage: (storage: ILocalStorage) => void;
error: (key: string, msg: string) => void;
report: () => void;
}
export class ErrorLog {
private client: ISettingsClient;
private storage: ILocalStorage = Storage();
constructor(client: ISettingsClient) {
this.client = client;
}
setClient(client: ISettingsClient) {
this.client = client;
}
setStorage(storage: ILocalStorage) {
this.storage = storage;
}
error = (key: string, msg: string) => {
const existKey = this.storage.get(key);
if (existKey === "") {
this.storage.set(key, msg);
}
};
report = () => {
// TODO:
// check last submitting, and set submit time
// report all errors to backend
// clean storage
};
}
const errorLogger = new ErrorLog(new SettingsClient(""));
export const ErrorLogger = (): IErrorLogger => {
return errorLogger;
};

View file

@ -0,0 +1,15 @@
import { Map } from "immutable";
export function getItemPath(dirPath: string, itemName: string): string {
return dirPath.endsWith("/")
? `${dirPath}${itemName}`
: `${dirPath}/${itemName}`;
}
export function getErrMsg(
msgPkg: Map<string, string>,
msg: string,
status: string
): string {
return `${msgPkg.get(msg)}: ${msgPkg.get(status)}`;
}