@servicetitan/log-service 18.1.0 → 19.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/global-error-handler.d.ts +6 -1
- package/dist/global-error-handler.d.ts.map +1 -1
- package/dist/global-error-handler.js +75 -26
- package/dist/global-error-handler.js.map +1 -1
- package/dist/serialize-with-metadata.js +3 -2
- package/dist/serialize-with-metadata.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/__snapshots__/serialize-with-metadata.test.ts.snap +6 -4
- package/src/__tests__/serialize-with-metadata.test.ts +1 -0
- package/src/global-error-handler.ts +73 -24
- package/src/serialize-with-metadata.ts +2 -2
|
@@ -2,7 +2,12 @@ import { Log } from './log';
|
|
|
2
2
|
export declare class GlobalErrorHandler {
|
|
3
3
|
private readonly logService;
|
|
4
4
|
constructor(logService: Log);
|
|
5
|
-
|
|
5
|
+
instrument(window: Window): void;
|
|
6
|
+
onError: (message: string, url?: string | undefined, line?: number | undefined, column?: number | undefined, error?: Error | undefined, isUnhandled?: boolean) => void;
|
|
7
|
+
onReject: (event: {
|
|
8
|
+
reason: unknown;
|
|
9
|
+
}) => void;
|
|
10
|
+
private dispatch;
|
|
6
11
|
private isIgnorable;
|
|
7
12
|
}
|
|
8
13
|
//# sourceMappingURL=global-error-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-error-handler.d.ts","sourceRoot":"","sources":["../src/global-error-handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAgB,MAAM,OAAO,CAAC;AAW1C,qBACa,kBAAkB;IACF,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,GAAG;IAEzD,
|
|
1
|
+
{"version":3,"file":"global-error-handler.d.ts","sourceRoot":"","sources":["../src/global-error-handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAgB,MAAM,OAAO,CAAC;AAW1C,qBACa,kBAAkB;IACF,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,GAAG;IAEzD,UAAU,CAAC,MAAM,EAAE,MAAM;IAKzB,OAAO,YACM,MAAM,8IA6CjB;IAEF,QAAQ,UAAW;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,UAiBpC;IAEF,OAAO,CAAC,QAAQ;IAwBhB,OAAO,CAAC,WAAW;CAgBtB"}
|
|
@@ -24,7 +24,7 @@ let GlobalErrorHandler = class GlobalErrorHandler {
|
|
|
24
24
|
writable: true,
|
|
25
25
|
value: logService
|
|
26
26
|
});
|
|
27
|
-
Object.defineProperty(this, "
|
|
27
|
+
Object.defineProperty(this, "onError", {
|
|
28
28
|
enumerable: true,
|
|
29
29
|
configurable: true,
|
|
30
30
|
writable: true,
|
|
@@ -46,40 +46,20 @@ let GlobalErrorHandler = class GlobalErrorHandler {
|
|
|
46
46
|
msg = (0, serialize_with_metadata_1.serializeWithMetadata)(message);
|
|
47
47
|
}
|
|
48
48
|
let err;
|
|
49
|
-
if (
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
err = error;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
50
53
|
const errorMessage = `Message - ${msg}${error ? ';Error - ' + (0, serialize_with_metadata_1.serializeWithMetadata)(error) : ''}`;
|
|
51
54
|
err = new Error(errorMessage);
|
|
52
55
|
err.stack += `\n\tat somewhere (${url}:${line}:${column})`;
|
|
53
56
|
err.code = 'NonUniform';
|
|
54
57
|
}
|
|
55
|
-
else {
|
|
56
|
-
err = error;
|
|
57
|
-
}
|
|
58
58
|
if (isUnhandled) {
|
|
59
59
|
err.category = 'UnhandledError';
|
|
60
60
|
err.code = (_a = err.code) !== null && _a !== void 0 ? _a : 'UnhandledError';
|
|
61
61
|
}
|
|
62
|
-
|
|
63
|
-
if (err.name === 'NotFoundError') {
|
|
64
|
-
this.logService.warning({
|
|
65
|
-
category: err.category,
|
|
66
|
-
code: err.code,
|
|
67
|
-
message: err.message,
|
|
68
|
-
data: err.data,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
this.logService.error({
|
|
73
|
-
error: err,
|
|
74
|
-
category: err.category,
|
|
75
|
-
code: err.code,
|
|
76
|
-
message: err.message,
|
|
77
|
-
data: err.data,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
// eslint-disable-next-line no-console
|
|
82
|
-
console.error(err);
|
|
62
|
+
this.dispatch(err);
|
|
83
63
|
}
|
|
84
64
|
catch (e) {
|
|
85
65
|
// eslint-disable-next-line no-console
|
|
@@ -89,6 +69,57 @@ let GlobalErrorHandler = class GlobalErrorHandler {
|
|
|
89
69
|
}
|
|
90
70
|
}
|
|
91
71
|
});
|
|
72
|
+
Object.defineProperty(this, "onReject", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true,
|
|
75
|
+
writable: true,
|
|
76
|
+
value: (event) => {
|
|
77
|
+
try {
|
|
78
|
+
const error = event.reason;
|
|
79
|
+
let err;
|
|
80
|
+
if (error instanceof Error) {
|
|
81
|
+
err = error;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const errorMessage = `Unhandled rejection - ${(0, serialize_with_metadata_1.serializeWithMetadata)(error)}`;
|
|
85
|
+
err = new Error(errorMessage);
|
|
86
|
+
err.code = 'NonUniform';
|
|
87
|
+
}
|
|
88
|
+
this.dispatch(err);
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
// eslint-disable-next-line no-console
|
|
92
|
+
console.error(e);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
instrument(window) {
|
|
98
|
+
consolidate(window, 'onerror', this.onError);
|
|
99
|
+
consolidate(window, 'onunhandledrejection', this.onReject);
|
|
100
|
+
}
|
|
101
|
+
dispatch(error) {
|
|
102
|
+
if (!error.noLog) {
|
|
103
|
+
if (error.name === 'NotFoundError') {
|
|
104
|
+
this.logService.warning({
|
|
105
|
+
category: error.category,
|
|
106
|
+
code: error.code,
|
|
107
|
+
message: error.message,
|
|
108
|
+
data: error.data,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.logService.error({
|
|
113
|
+
error,
|
|
114
|
+
category: error.category,
|
|
115
|
+
code: error.code,
|
|
116
|
+
message: error.message,
|
|
117
|
+
data: error.data,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// eslint-disable-next-line no-console
|
|
122
|
+
console.error(error);
|
|
92
123
|
}
|
|
93
124
|
isIgnorable(message) {
|
|
94
125
|
if (typeof message !== 'string') {
|
|
@@ -111,4 +142,22 @@ GlobalErrorHandler = __decorate([
|
|
|
111
142
|
__metadata("design:paramtypes", [log_1.Log])
|
|
112
143
|
], GlobalErrorHandler);
|
|
113
144
|
exports.GlobalErrorHandler = GlobalErrorHandler;
|
|
145
|
+
function consolidate(object, methodName, fn) {
|
|
146
|
+
if (typeof object[methodName] === 'function') {
|
|
147
|
+
const fnPrev = object[methodName];
|
|
148
|
+
object[methodName] = (...args) => {
|
|
149
|
+
try {
|
|
150
|
+
fn(...args);
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
fnPrev(...args);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (object[methodName] != null) {
|
|
159
|
+
throw new TypeError('attempt to instrument non-function value');
|
|
160
|
+
}
|
|
161
|
+
object[methodName] = fn;
|
|
162
|
+
}
|
|
114
163
|
//# sourceMappingURL=global-error-handler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-error-handler.js","sourceRoot":"","sources":["../src/global-error-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA6D;AAE7D,+BAA0C;AAC1C,uEAAkE;AAWlE,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAC3B,YAA0C,UAAe;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AS;gBACN,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;aACnB;QACL,CAAC,CAAC;QACF,OAAO;KACV;IACD,IAAI,MAAM,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE;QAC5B,MAAM,IAAI,SAAS,CAAC,0CAA0C,CAAC,CAAC;KACnE;IAED,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;AAC5B,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.serializeWithMetadata = void 0;
|
|
4
4
|
function serializeWithMetadata(obj) {
|
|
5
|
+
var _a, _b;
|
|
5
6
|
let result = `Type:${typeof obj}`;
|
|
6
7
|
try {
|
|
7
8
|
if (typeof obj === 'object') {
|
|
@@ -9,13 +10,13 @@ function serializeWithMetadata(obj) {
|
|
|
9
10
|
if (obj instanceof Event) {
|
|
10
11
|
result += `|EventType:${obj.type}`;
|
|
11
12
|
}
|
|
12
|
-
result += `|Value:${JSON.stringify(obj).substr(0, 100)}`;
|
|
13
|
+
result += `|Value:${(_a = JSON.stringify(obj)) === null || _a === void 0 ? void 0 : _a.substr(0, 100)}`;
|
|
13
14
|
}
|
|
14
15
|
else if (typeof obj === 'function') {
|
|
15
16
|
result += `|Name:${obj.name}`;
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
18
|
-
result += `|Value:${JSON.stringify(obj).substr(0, 100)}`;
|
|
19
|
+
result += `|Value:${(_b = JSON.stringify(obj)) === null || _b === void 0 ? void 0 : _b.substr(0, 100)}`;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize-with-metadata.js","sourceRoot":"","sources":["../src/serialize-with-metadata.ts"],"names":[],"mappings":";;;AAAA,SAAgB,qBAAqB,CAAC,GAAY
|
|
1
|
+
{"version":3,"file":"serialize-with-metadata.js","sourceRoot":"","sources":["../src/serialize-with-metadata.ts"],"names":[],"mappings":";;;AAAA,SAAgB,qBAAqB,CAAC,GAAY;;IAC9C,IAAI,MAAM,GAAG,QAAQ,OAAO,GAAG,EAAE,CAAC;IAClC,IAAI;QACA,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;YACzB,MAAM,IAAI,gBAAgB,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,WAAW,CAAC,IAAI,EAAE,CAAC;YAClD,IAAI,GAAG,YAAY,KAAK,EAAE;gBACtB,MAAM,IAAI,cAAc,GAAG,CAAC,IAAI,EAAE,CAAC;aACtC;YACD,MAAM,IAAI,UAAU,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,0CAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;SAC7D;aAAM,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;YAClC,MAAM,IAAI,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC;SACjC;aAAM;YACH,MAAM,IAAI,UAAU,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,0CAAE,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;SAC7D;KACJ;IAAC,OAAO,CAAC,EAAE;QACR,MAAM,IAAI,sBAAsB,CAAC;QACjC,IAAI,CAAC,YAAY,KAAK,EAAE;YACpB,MAAM,IAAI,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;SAC7C;KACJ;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AArBD,sDAqBC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/log-service",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "19.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/log-service",
|
|
6
6
|
"repository": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"src"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@servicetitan/react-ioc": "^
|
|
18
|
+
"@servicetitan/react-ioc": "^19.0.0",
|
|
19
19
|
"@types/lodash.throttle": "~4.1.6",
|
|
20
20
|
"axios": "~0.24.0",
|
|
21
21
|
"mobx": "~6.3.7",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"cli": {
|
|
37
37
|
"webpack": false
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "efb844833047aa20f082a4f71dfd2c6af06937a9"
|
|
40
40
|
}
|
|
@@ -8,13 +8,15 @@ exports[`Serialize with metadata 2 1`] = `"Type:object|Constructor:Object|Value:
|
|
|
8
8
|
|
|
9
9
|
exports[`Serialize with metadata 3 1`] = `"Type:object|Constructor:undefined|Value:null"`;
|
|
10
10
|
|
|
11
|
-
exports[`Serialize with metadata 4 1`] = `"Type:
|
|
11
|
+
exports[`Serialize with metadata 4 1`] = `"Type:undefined|Value:undefined"`;
|
|
12
12
|
|
|
13
|
-
exports[`Serialize with metadata 5 1`] = `"Type:
|
|
13
|
+
exports[`Serialize with metadata 5 1`] = `"Type:function|Name:abc"`;
|
|
14
14
|
|
|
15
|
-
exports[`Serialize with metadata 6 1`] = `"Type:
|
|
15
|
+
exports[`Serialize with metadata 6 1`] = `"Type:number|Value:123"`;
|
|
16
16
|
|
|
17
|
-
exports[`Serialize with metadata 7 1`] = `
|
|
17
|
+
exports[`Serialize with metadata 7 1`] = `"Type:object|Constructor:Event|EventType:MyEvent|Value:{\\"isTrusted\\":false}"`;
|
|
18
|
+
|
|
19
|
+
exports[`Serialize with metadata 8 1`] = `
|
|
18
20
|
"Type:object|Constructor:Object|Unable to serialize: Converting circular structure to JSON
|
|
19
21
|
--> starting at object with constructor 'Object'
|
|
20
22
|
| "
|
|
@@ -15,7 +15,12 @@ interface ExtendedError extends Error {
|
|
|
15
15
|
export class GlobalErrorHandler {
|
|
16
16
|
constructor(@inject(Log) private readonly logService: Log) {}
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
instrument(window: Window) {
|
|
19
|
+
consolidate(window, 'onerror', this.onError);
|
|
20
|
+
consolidate(window, 'onunhandledrejection', this.onReject);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
onError = (
|
|
19
24
|
message: string,
|
|
20
25
|
url?: string,
|
|
21
26
|
line?: number,
|
|
@@ -39,41 +44,22 @@ export class GlobalErrorHandler {
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
let err: ExtendedError;
|
|
42
|
-
if (
|
|
47
|
+
if (error instanceof Error) {
|
|
48
|
+
err = error;
|
|
49
|
+
} else {
|
|
43
50
|
const errorMessage = `Message - ${msg}${
|
|
44
51
|
error ? ';Error - ' + serializeWithMetadata(error) : ''
|
|
45
52
|
}`;
|
|
46
53
|
err = new Error(errorMessage);
|
|
47
54
|
err.stack += `\n\tat somewhere (${url}:${line}:${column})`;
|
|
48
55
|
err.code = 'NonUniform';
|
|
49
|
-
} else {
|
|
50
|
-
err = error;
|
|
51
56
|
}
|
|
52
57
|
if (isUnhandled) {
|
|
53
58
|
err.category = 'UnhandledError';
|
|
54
59
|
err.code = err.code ?? 'UnhandledError';
|
|
55
60
|
}
|
|
56
|
-
if (!err.noLog) {
|
|
57
|
-
if (err.name === 'NotFoundError') {
|
|
58
|
-
this.logService.warning({
|
|
59
|
-
category: err.category,
|
|
60
|
-
code: err.code,
|
|
61
|
-
message: err.message,
|
|
62
|
-
data: err.data,
|
|
63
|
-
});
|
|
64
|
-
} else {
|
|
65
|
-
this.logService.error({
|
|
66
|
-
error: err,
|
|
67
|
-
category: err.category,
|
|
68
|
-
code: err.code,
|
|
69
|
-
message: err.message,
|
|
70
|
-
data: err.data,
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
61
|
|
|
75
|
-
|
|
76
|
-
console.error(err);
|
|
62
|
+
this.dispatch(err);
|
|
77
63
|
} catch (e) {
|
|
78
64
|
// eslint-disable-next-line no-console
|
|
79
65
|
console.error(message);
|
|
@@ -82,6 +68,49 @@ export class GlobalErrorHandler {
|
|
|
82
68
|
}
|
|
83
69
|
};
|
|
84
70
|
|
|
71
|
+
onReject = (event: { reason: unknown }) => {
|
|
72
|
+
try {
|
|
73
|
+
const error = event.reason;
|
|
74
|
+
let err: ExtendedError;
|
|
75
|
+
if (error instanceof Error) {
|
|
76
|
+
err = error;
|
|
77
|
+
} else {
|
|
78
|
+
const errorMessage = `Unhandled rejection - ${serializeWithMetadata(error)}`;
|
|
79
|
+
err = new Error(errorMessage);
|
|
80
|
+
err.code = 'NonUniform';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
this.dispatch(err);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
console.error(e);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
private dispatch(error: ExtendedError) {
|
|
91
|
+
if (!error.noLog) {
|
|
92
|
+
if (error.name === 'NotFoundError') {
|
|
93
|
+
this.logService.warning({
|
|
94
|
+
category: error.category,
|
|
95
|
+
code: error.code,
|
|
96
|
+
message: error.message,
|
|
97
|
+
data: error.data,
|
|
98
|
+
});
|
|
99
|
+
} else {
|
|
100
|
+
this.logService.error({
|
|
101
|
+
error,
|
|
102
|
+
category: error.category,
|
|
103
|
+
code: error.code,
|
|
104
|
+
message: error.message,
|
|
105
|
+
data: error.data,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// eslint-disable-next-line no-console
|
|
111
|
+
console.error(error);
|
|
112
|
+
}
|
|
113
|
+
|
|
85
114
|
private isIgnorable(message: string) {
|
|
86
115
|
if (typeof message !== 'string') {
|
|
87
116
|
return false;
|
|
@@ -99,3 +128,23 @@ export class GlobalErrorHandler {
|
|
|
99
128
|
return ignoreSubstrings.some(sub => message.includes(sub));
|
|
100
129
|
}
|
|
101
130
|
}
|
|
131
|
+
|
|
132
|
+
function consolidate(object: { [key: string]: any }, methodName: string, fn: Function) {
|
|
133
|
+
if (typeof object[methodName] === 'function') {
|
|
134
|
+
const fnPrev = object[methodName];
|
|
135
|
+
|
|
136
|
+
object[methodName] = (...args: unknown[]) => {
|
|
137
|
+
try {
|
|
138
|
+
fn(...args);
|
|
139
|
+
} finally {
|
|
140
|
+
fnPrev(...args);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (object[methodName] != null) {
|
|
146
|
+
throw new TypeError('attempt to instrument non-function value');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
object[methodName] = fn;
|
|
150
|
+
}
|
|
@@ -6,11 +6,11 @@ export function serializeWithMetadata(obj: unknown) {
|
|
|
6
6
|
if (obj instanceof Event) {
|
|
7
7
|
result += `|EventType:${obj.type}`;
|
|
8
8
|
}
|
|
9
|
-
result += `|Value:${JSON.stringify(obj)
|
|
9
|
+
result += `|Value:${JSON.stringify(obj)?.substr(0, 100)}`;
|
|
10
10
|
} else if (typeof obj === 'function') {
|
|
11
11
|
result += `|Name:${obj.name}`;
|
|
12
12
|
} else {
|
|
13
|
-
result += `|Value:${JSON.stringify(obj)
|
|
13
|
+
result += `|Value:${JSON.stringify(obj)?.substr(0, 100)}`;
|
|
14
14
|
}
|
|
15
15
|
} catch (e) {
|
|
16
16
|
result += '|Unable to serialize';
|