Commit 142ecbe7 by 杨铁龙

日志支持小程序

parent 51763f55
Showing with 34 additions and 20 deletions
import Axios, { AxiosResponse } from "axios"; import Axios, { AxiosResponse, AxiosAdapter } from "axios";
import { UniplatSdk } from "uniplat-sdk"; import { UniplatSdk } from "uniplat-sdk";
import { ImEnvironment } from "../model"; import { ImEnvironment } from "../model";
export const enum Product { export const enum Product {
Default = 'default', Default = "default",
QqxbWeixin = 'qqxb-weixin', QqxbWeixin = "qqxb-weixin",
QqxbApp = 'qqxb-app', QqxbApp = "qqxb-app",
Fulibao = 'fulibao', Fulibao = "fulibao",
HrManager = 'hr-manager', HrManager = "hr-manager",
Hrs100 = 'hrs100', Hrs100 = "hrs100",
HrsApp = 'hrs-app', HrsApp = "hrs-app",
BiJie = 'bi-jie', BiJie = "bi-jie",
Cashier = 'cashier', Cashier = "cashier",
Uniplat = "uniplat", Uniplat = "uniplat",
DeShengJiuYeBao = 'de-sheng-jiu-ye-bao' DeShengJiuYeBao = "de-sheng-jiu-ye-bao",
} }
const enum ProductTable { const enum ProductTable {
...@@ -26,6 +26,7 @@ export interface SdkMonitorOption { ...@@ -26,6 +26,7 @@ export interface SdkMonitorOption {
userAgent?: boolean; userAgent?: boolean;
envir: ImEnvironment; envir: ImEnvironment;
product: Product; product: Product;
call?: (r: any) => void;
} }
class WebMonitor { class WebMonitor {
...@@ -33,6 +34,7 @@ class WebMonitor { ...@@ -33,6 +34,7 @@ class WebMonitor {
private envir = ImEnvironment.Dev; private envir = ImEnvironment.Dev;
private product = Product.Default; private product = Product.Default;
private readonly url = "https://pre-hrs-monitor.hrs100.com"; private readonly url = "https://pre-hrs-monitor.hrs100.com";
private adapter: AxiosAdapter | undefined;
public updateKey(key: string) { public updateKey(key: string) {
this.key = key; this.key = key;
...@@ -42,6 +44,7 @@ class WebMonitor { ...@@ -42,6 +44,7 @@ class WebMonitor {
private buildHeaders() { private buildHeaders() {
return { return {
headers: { authorization: "cdd0a34e-f537-4e5b-808e-2ba06af21845" }, headers: { authorization: "cdd0a34e-f537-4e5b-808e-2ba06af21845" },
adapter: this.adapter,
}; };
} }
...@@ -85,13 +88,22 @@ class WebMonitor { ...@@ -85,13 +88,22 @@ class WebMonitor {
); );
} }
public useSdk(sdk: UniplatSdk, options: SdkMonitorOption) { public useSdk(
sdk: UniplatSdk,
options: SdkMonitorOption,
adapter?: AxiosAdapter
) {
this.envir = options.envir; this.envir = options.envir;
this.product = options.product; this.product = options.product;
sdk.events.addUniversalErrorResponseCallback((r: AxiosResponse<any>) => { this.adapter = adapter;
sdk.events.addUniversalErrorResponseCallback(
(r: AxiosResponse<any>) => {
options.call && options.call(r);
if (this.enable()) { if (this.enable()) {
const msg: string[] = []; const msg: string[] = [];
msg.push(`URL: ${decodeURIComponent(r.config.url as string)}`); msg.push(
`URL: ${decodeURIComponent(r.config.url as string)}`
);
msg.push(`Token: ${sdk.global.jwtToken}`); msg.push(`Token: ${sdk.global.jwtToken}`);
const header = r.config.headers; const header = r.config.headers;
if (header) { if (header) {
...@@ -102,18 +114,20 @@ class WebMonitor { ...@@ -102,18 +114,20 @@ class WebMonitor {
options && options &&
options.userAgent && options.userAgent &&
msg.push(`UserAgent: ${window.navigator.userAgent}`); msg.push(`UserAgent: ${window.navigator.userAgent}`);
r.config && r.config.data && msg.push(`Payload: ${JSON.stringify(r.config.data)}`); r.config &&
r.config.data &&
msg.push(`Payload: ${JSON.stringify(r.config.data)}`);
msg.push( msg.push(
`Exception: ${((r.data.error as string) || "").substring( `Exception: ${(
0, (r.data.error as string) || ""
500 ).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