feat(fe/errors): add error log and prompt related pieces
This commit is contained in:
parent
ba17416755
commit
f0e898d1ae
3 changed files with 66 additions and 0 deletions
5
src/client/web/src/common/errors.ts
Normal file
5
src/client/web/src/common/errors.ts
Normal 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";
|
46
src/client/web/src/common/log_error.ts
Normal file
46
src/client/web/src/common/log_error.ts
Normal 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;
|
||||
};
|
15
src/client/web/src/common/utils.ts
Normal file
15
src/client/web/src/common/utils.ts
Normal 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)}`;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue