Commit 142ecbe7 by 杨铁龙

日志支持小程序

parent 51763f55
Showing with 48 additions and 34 deletions
import Axios, { AxiosResponse } from "axios";
import Axios, { AxiosResponse, AxiosAdapter } from "axios";
import { UniplatSdk } from "uniplat-sdk";
import { ImEnvironment } from "../model";
export const enum Product {
Default = 'default',
QqxbWeixin = 'qqxb-weixin',
QqxbApp = 'qqxb-app',
Fulibao = 'fulibao',
HrManager = 'hr-manager',
Hrs100 = 'hrs100',
HrsApp = 'hrs-app',
BiJie = 'bi-jie',
Cashier = 'cashier',
Default = "default",
QqxbWeixin = "qqxb-weixin",
QqxbApp = "qqxb-app",
Fulibao = "fulibao",
HrManager = "hr-manager",
Hrs100 = "hrs100",
HrsApp = "hrs-app",
BiJie = "bi-jie",
Cashier = "cashier",
Uniplat = "uniplat",
DeShengJiuYeBao = 'de-sheng-jiu-ye-bao'
DeShengJiuYeBao = "de-sheng-jiu-ye-bao",
}
const enum ProductTable {
......@@ -26,6 +26,7 @@ export interface SdkMonitorOption {
userAgent?: boolean;
envir: ImEnvironment;
product: Product;
call?: (r: any) => void;
}
class WebMonitor {
......@@ -33,6 +34,7 @@ class WebMonitor {
private envir = ImEnvironment.Dev;
private product = Product.Default;
private readonly url = "https://pre-hrs-monitor.hrs100.com";
private adapter: AxiosAdapter | undefined;
public updateKey(key: string) {
this.key = key;
......@@ -42,6 +44,7 @@ class WebMonitor {
private buildHeaders() {
return {
headers: { authorization: "cdd0a34e-f537-4e5b-808e-2ba06af21845" },
adapter: this.adapter,
};
}
......@@ -85,35 +88,46 @@ class WebMonitor {
);
}
public useSdk(sdk: UniplatSdk, options: SdkMonitorOption) {
public useSdk(
sdk: UniplatSdk,
options: SdkMonitorOption,
adapter?: AxiosAdapter
) {
this.envir = options.envir;
this.product = options.product;
sdk.events.addUniversalErrorResponseCallback((r: AxiosResponse<any>) => {
if (this.enable()) {
const msg: string[] = [];
msg.push(`URL: ${decodeURIComponent(r.config.url as string)}`);
msg.push(`Token: ${sdk.global.jwtToken}`);
const header = r.config.headers;
if (header) {
msg.push(`CurrentOrg: ${header.CurrentOrg}`);
msg.push(`Scenes: ${header.Scenes}`);
}
this.adapter = adapter;
sdk.events.addUniversalErrorResponseCallback(
(r: AxiosResponse<any>) => {
options.call && options.call(r);
if (this.enable()) {
const msg: string[] = [];
msg.push(
`URL: ${decodeURIComponent(r.config.url as string)}`
);
msg.push(`Token: ${sdk.global.jwtToken}`);
const header = r.config.headers;
if (header) {
msg.push(`CurrentOrg: ${header.CurrentOrg}`);
msg.push(`Scenes: ${header.Scenes}`);
}
options &&
options.userAgent &&
msg.push(`UserAgent: ${window.navigator.userAgent}`);
r.config && r.config.data && msg.push(`Payload: ${JSON.stringify(r.config.data)}`);
options &&
options.userAgent &&
msg.push(`UserAgent: ${window.navigator.userAgent}`);
r.config &&
r.config.data &&
msg.push(`Payload: ${JSON.stringify(r.config.data)}`);
msg.push(
`Exception: ${((r.data.error as string) || "").substring(
0,
500
)}`
);
msg.push(
`Exception: ${(
(r.data.error as string) || ""
).substring(0, 500)}`
);
r && r.config && this.error(msg.join("\n"));
r && r.config && this.error(msg.join("\n"));
}
}
});
);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment