@servicetitan/log-service 17.4.0 → 17.5.4
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 +1 -1
- package/dist/global-error-handler.d.ts.map +1 -1
- package/dist/global-error-handler.js +51 -43
- package/dist/global-error-handler.js.map +1 -1
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +4 -2
- package/dist/log.js.map +1 -1
- package/dist/serialize-with-metadata.d.ts +2 -0
- package/dist/serialize-with-metadata.d.ts.map +1 -0
- package/dist/serialize-with-metadata.js +30 -0
- package/dist/serialize-with-metadata.js.map +1 -0
- package/package.json +5 -5
- package/src/__tests__/__snapshots__/serialize-with-metadata.test.ts.snap +21 -0
- package/src/__tests__/serialize-with-metadata.test.ts +21 -0
- package/src/global-error-handler.ts +54 -44
- package/src/log.tsx +4 -2
- package/src/serialize-with-metadata.ts +22 -0
|
@@ -2,7 +2,7 @@ import { Log } from './log';
|
|
|
2
2
|
export declare class GlobalErrorHandler {
|
|
3
3
|
private readonly logService;
|
|
4
4
|
constructor(logService: Log);
|
|
5
|
-
errorHandler: (message: string
|
|
5
|
+
errorHandler: (message: string, url?: string | undefined, line?: number | undefined, column?: number | undefined, error?: Error | undefined, isUnhandled?: boolean) => void;
|
|
6
6
|
private isIgnorable;
|
|
7
7
|
}
|
|
8
8
|
//# 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;
|
|
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,YAAY,YACC,MAAM,8IAgEjB;IAEF,OAAO,CAAC,WAAW;CAgBtB"}
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.GlobalErrorHandler = void 0;
|
|
16
16
|
const react_ioc_1 = require("@servicetitan/react-ioc");
|
|
17
17
|
const log_1 = require("./log");
|
|
18
|
+
const serialize_with_metadata_1 = require("./serialize-with-metadata");
|
|
18
19
|
let GlobalErrorHandler = class GlobalErrorHandler {
|
|
19
20
|
constructor(logService) {
|
|
20
21
|
Object.defineProperty(this, "logService", {
|
|
@@ -27,58 +28,65 @@ let GlobalErrorHandler = class GlobalErrorHandler {
|
|
|
27
28
|
enumerable: true,
|
|
28
29
|
configurable: true,
|
|
29
30
|
writable: true,
|
|
30
|
-
value: (message, url, line, column,
|
|
31
|
+
value: (message, url, line, column, error, isUnhandled = true) => {
|
|
31
32
|
var _a;
|
|
32
|
-
if (this.isIgnorable(message)) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
let messageString = '';
|
|
36
33
|
try {
|
|
37
|
-
if (message
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
if (this.isIgnorable(message)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
let msg = '';
|
|
38
|
+
if (typeof message === 'string') {
|
|
39
|
+
msg = message;
|
|
42
40
|
}
|
|
43
41
|
else {
|
|
44
|
-
|
|
42
|
+
/*
|
|
43
|
+
* By specification message is always a string
|
|
44
|
+
* this condition covers manual nonuniform window.onerror call
|
|
45
|
+
*/
|
|
46
|
+
msg = (0, serialize_with_metadata_1.serializeWithMetadata)(message);
|
|
45
47
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
error.stack += `\n\tat somewhere (${url}:${line}:${column})`;
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
error = _error;
|
|
56
|
-
}
|
|
57
|
-
if (isUnhandled) {
|
|
58
|
-
error.category = 'UnhandledError';
|
|
59
|
-
error.code = (_a = error.code) !== null && _a !== void 0 ? _a : 'UnhandledError';
|
|
60
|
-
}
|
|
61
|
-
if (!error.noLog) {
|
|
62
|
-
if (error.name === 'NotFoundError') {
|
|
63
|
-
this.logService.warning({
|
|
64
|
-
category: error.category,
|
|
65
|
-
code: error.code,
|
|
66
|
-
message: error.message,
|
|
67
|
-
data: error.data,
|
|
68
|
-
});
|
|
48
|
+
let err;
|
|
49
|
+
if (!error || !(error instanceof Error)) {
|
|
50
|
+
const errorMessage = `Message - ${msg}${error ? ';Error - ' + (0, serialize_with_metadata_1.serializeWithMetadata)(error) : ''}`;
|
|
51
|
+
err = new Error(errorMessage);
|
|
52
|
+
err.stack += `\n\tat somewhere (${url}:${line}:${column})`;
|
|
53
|
+
err.code = 'NonUniform';
|
|
69
54
|
}
|
|
70
55
|
else {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
err = error;
|
|
57
|
+
}
|
|
58
|
+
if (isUnhandled) {
|
|
59
|
+
err.category = 'UnhandledError';
|
|
60
|
+
err.code = (_a = err.code) !== null && _a !== void 0 ? _a : 'UnhandledError';
|
|
61
|
+
}
|
|
62
|
+
if (!err.noLog) {
|
|
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
|
+
}
|
|
78
80
|
}
|
|
81
|
+
// eslint-disable-next-line no-console
|
|
82
|
+
console.error(err);
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
// eslint-disable-next-line no-console
|
|
86
|
+
console.error(message);
|
|
87
|
+
// eslint-disable-next-line no-console
|
|
88
|
+
console.error(e);
|
|
79
89
|
}
|
|
80
|
-
// eslint-disable-next-line no-console
|
|
81
|
-
console.error(error);
|
|
82
90
|
}
|
|
83
91
|
});
|
|
84
92
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-error-handler.js","sourceRoot":"","sources":["../src/global-error-handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uDAA6D;AAE7D,+BAA0C;
|
|
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;;;;;mBAAf;;QAE1C;;;;mBAAe,CACX,OAAe,EACf,GAAY,EACZ,IAAa,EACb,MAAe,EACf,KAAa,EACb,WAAW,GAAG,IAAI,EACpB,EAAE;;gBACA,IAAI;oBACA,IAAI,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE;wBAC3B,OAAO;qBACV;oBACD,IAAI,GAAG,GAAG,EAAE,CAAC;oBACb,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;wBAC7B,GAAG,GAAG,OAAO,CAAC;qBACjB;yBAAM;wBACH;;;2BAGG;wBACH,GAAG,GAAG,IAAA,+CAAqB,EAAC,OAAO,CAAC,CAAC;qBACxC;oBAED,IAAI,GAAkB,CAAC;oBACvB,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC,EAAE;wBACrC,MAAM,YAAY,GAAG,aAAa,GAAG,GACjC,KAAK,CAAC,CAAC,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CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;iBACpB;YACL,CAAC;WAAC;IAnE0D,CAAC;IAqErD,WAAW,CAAC,OAAe;QAC/B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;YAC7B,OAAO,KAAK,CAAC;SAChB;QAED,MAAM,gBAAgB,GAAG;YACrB,mCAAmC;YACnC,QAAQ;YACR,aAAa;YACb,gBAAgB;YAChB,yCAAyC;YACzC,gCAAgC;SACnC,CAAC;QAEF,OAAO,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/D,CAAC;CACJ,CAAA;AAtFY,kBAAkB;IAD9B,IAAA,sBAAU,GAAE;IAEI,WAAA,IAAA,kBAAM,EAAC,SAAG,CAAC,CAAA;qCAA8B,SAAG;GADhD,kBAAkB,CAsF9B;AAtFY,gDAAkB"}
|
package/dist/log.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAG3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAG3B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,WAAW,YAAa,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAAG;AAEzF,MAAM,WAAW,QAAQ;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EA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CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAI1B,OAAO,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAIhC,KAAK,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAM5B,OAAO,CAAC,KAAK;IAIb,OAAO,CAAC,MAAM;IAiBd,OAAO,CAAC,WAAW;IAiBnB,OAAO,CAAC,WAAW;CAStB"}
|
package/dist/log.js
CHANGED
|
@@ -31,6 +31,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
31
31
|
const lodash_throttle_1 = __importDefault(require("lodash.throttle"));
|
|
32
32
|
const react_ioc_1 = require("@servicetitan/react-ioc");
|
|
33
33
|
const log_storage_1 = require("./log-storage");
|
|
34
|
+
const serialize_with_metadata_1 = require("./serialize-with-metadata");
|
|
34
35
|
var LogEntryType;
|
|
35
36
|
(function (LogEntryType) {
|
|
36
37
|
LogEntryType["Info"] = "Info";
|
|
@@ -63,8 +64,9 @@ let Log = class Log {
|
|
|
63
64
|
return this.store(this.expand(LogEntryType.Warning, entry));
|
|
64
65
|
}
|
|
65
66
|
error(entry) {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.error(entry);
|
|
66
69
|
return this.errorLogHandler.handle(this.expandError(entry)); // with errorLogHandler throttling
|
|
67
|
-
// return this.store(this.expandError(entry)); // without errorLogHandler throttling
|
|
68
70
|
}
|
|
69
71
|
store(entry) {
|
|
70
72
|
return this.logStorage.store(entry);
|
|
@@ -79,7 +81,7 @@ let Log = class Log {
|
|
|
79
81
|
error = entry.error;
|
|
80
82
|
}
|
|
81
83
|
else {
|
|
82
|
-
error = new Error(
|
|
84
|
+
error = new Error((0, serialize_with_metadata_1.serializeWithMetadata)(entry.error));
|
|
83
85
|
}
|
|
84
86
|
const _a = this.expand(LogEntryType.Error, entry), { message } = _a, rest = __rest(_a, ["message"]);
|
|
85
87
|
return Object.assign(Object.assign({ message: message !== null && message !== void 0 ? message : error.message }, rest), { error });
|
package/dist/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sEAAuC;AACvC,uDAAoF;AACpF,+CAA2C;
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sEAAuC;AACvC,uDAAoF;AACpF,+CAA2C;AAC3C,uEAAkE;AAyBlE,IAAY,YAIX;AAJD,WAAY,YAAY;IACpB,6BAAa,CAAA;IACb,mCAAmB,CAAA;IACnB,+BAAe,CAAA;AACnB,CAAC,EAJW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAIvB;AAqBY,QAAA,gBAAgB,GAAG,IAAA,uBAAW,EAAY,kBAAkB,CAAC,CAAC;AAEpE,MAAM,iBAAiB,GAA6B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAChF,uBAAC,oBAAQ,kBAAC,UAAU,EAAE,CAAC,EAAE,OAAO,EAAE,wBAAgB,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,gBAAG,QAAQ,YAAY,CAChG,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAGF,IAAa,GAAG,GAAhB,MAAa,GAAG;IAGZ,YAAiD,UAAsB;;;;;mBAAtB;;QAFjD;;;;;WAAyC;QAGrC,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IACtE,CAAC;IAED,IAAI,CAAC,KAAc;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,OAAO,CAAC,KAAiB;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC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EAAE;WAAC;IAiB3C,CAAC;IAfG,GAAG,CAAC,GAAuC,EAAE,KAAQ;QACjD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;IAC7C,CAAC;IAED,GAAG,CAAC,GAAuC;QACvC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED,SAAS;QACL,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACrB,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-with-metadata.d.ts","sourceRoot":"","sources":["../src/serialize-with-metadata.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,UAqBjD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeWithMetadata = void 0;
|
|
4
|
+
function serializeWithMetadata(obj) {
|
|
5
|
+
let result = `Type:${typeof obj}`;
|
|
6
|
+
try {
|
|
7
|
+
if (typeof obj === 'object') {
|
|
8
|
+
result += `|Constructor:${obj === null || obj === void 0 ? void 0 : obj.constructor.name}`;
|
|
9
|
+
if (obj instanceof Event) {
|
|
10
|
+
result += `|EventType:${obj.type}`;
|
|
11
|
+
}
|
|
12
|
+
result += `|Value:${JSON.stringify(obj).substr(0, 100)}`;
|
|
13
|
+
}
|
|
14
|
+
else if (typeof obj === 'function') {
|
|
15
|
+
result += `|Name:${obj.name}`;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
result += `|Value:${JSON.stringify(obj).substr(0, 100)}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
result += '|Unable to serialize';
|
|
23
|
+
if (e instanceof Error) {
|
|
24
|
+
result += `: ${e.message.substr(0, 100)}`;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
exports.serializeWithMetadata = serializeWithMetadata;
|
|
30
|
+
//# sourceMappingURL=serialize-with-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;SAC5D;aAAM,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;YAClC,MAAM,IAAI,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC;SACjC;aAAM;YACH,MAAM,IAAI,UAAU,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;SAC5D;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": "17.4
|
|
3
|
+
"version": "17.5.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"homepage": "https://docs.st.dev/docs/frontend/log-service",
|
|
6
6
|
"repository": {
|
|
@@ -15,16 +15,16 @@
|
|
|
15
15
|
"src"
|
|
16
16
|
],
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@servicetitan/react-ioc": "^17.4
|
|
18
|
+
"@servicetitan/react-ioc": "^17.5.4",
|
|
19
19
|
"@types/lodash.throttle": "~4.1.6",
|
|
20
20
|
"axios": "~0.24.0",
|
|
21
|
-
"mobx": "~6.3.
|
|
21
|
+
"mobx": "~6.3.7",
|
|
22
22
|
"react": "~17.0.2"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@servicetitan/react-ioc": "^17.0.0",
|
|
26
26
|
"axios": "~0.24.0",
|
|
27
|
-
"mobx": "~6.3.
|
|
27
|
+
"mobx": "~6.3.7",
|
|
28
28
|
"react": "~17.0.2"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"cli": {
|
|
37
37
|
"webpack": false
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "acf1acc24831b47478386625f8df3f4496816cf0"
|
|
40
40
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Serialize with metadata 0 1`] = `"Type:object|Constructor:Error|Value:{}"`;
|
|
4
|
+
|
|
5
|
+
exports[`Serialize with metadata 1 1`] = `"Type:object|Constructor:Abc|Value:{\\"a\\":1}"`;
|
|
6
|
+
|
|
7
|
+
exports[`Serialize with metadata 2 1`] = `"Type:object|Constructor:Object|Value:{\\"b\\":1}"`;
|
|
8
|
+
|
|
9
|
+
exports[`Serialize with metadata 3 1`] = `"Type:object|Constructor:undefined|Value:null"`;
|
|
10
|
+
|
|
11
|
+
exports[`Serialize with metadata 4 1`] = `"Type:function|Name:abc"`;
|
|
12
|
+
|
|
13
|
+
exports[`Serialize with metadata 5 1`] = `"Type:number|Value:123"`;
|
|
14
|
+
|
|
15
|
+
exports[`Serialize with metadata 6 1`] = `"Type:object|Constructor:Event|EventType:MyEvent|Value:{\\"isTrusted\\":false}"`;
|
|
16
|
+
|
|
17
|
+
exports[`Serialize with metadata 7 1`] = `
|
|
18
|
+
"Type:object|Constructor:Object|Unable to serialize: Converting circular structure to JSON
|
|
19
|
+
--> starting at object with constructor 'Object'
|
|
20
|
+
| "
|
|
21
|
+
`;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { serializeWithMetadata } from '../serialize-with-metadata';
|
|
2
|
+
|
|
3
|
+
class Abc {
|
|
4
|
+
a = 1;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const cyclicObject = { a: { b: {} } };
|
|
8
|
+
cyclicObject.a.b = cyclicObject;
|
|
9
|
+
|
|
10
|
+
test.each([
|
|
11
|
+
[new Error('Error')],
|
|
12
|
+
[new Abc()],
|
|
13
|
+
[{ b: 1 }],
|
|
14
|
+
[null],
|
|
15
|
+
[function abc() {}],
|
|
16
|
+
[123],
|
|
17
|
+
[new Event('MyEvent')],
|
|
18
|
+
[cyclicObject],
|
|
19
|
+
])('Serialize with metadata %#', error => {
|
|
20
|
+
expect(serializeWithMetadata(error)).toMatchSnapshot();
|
|
21
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { injectable, inject } from '@servicetitan/react-ioc';
|
|
2
2
|
|
|
3
3
|
import { Log, ArbitaryData } from './log';
|
|
4
|
+
import { serializeWithMetadata } from './serialize-with-metadata';
|
|
4
5
|
|
|
5
6
|
interface ExtendedError extends Error {
|
|
6
7
|
category?: string;
|
|
@@ -15,64 +16,73 @@ export class GlobalErrorHandler {
|
|
|
15
16
|
constructor(@inject(Log) private readonly logService: Log) {}
|
|
16
17
|
|
|
17
18
|
errorHandler = (
|
|
18
|
-
message: string
|
|
19
|
+
message: string,
|
|
19
20
|
url?: string,
|
|
20
21
|
line?: number,
|
|
21
22
|
column?: number,
|
|
22
|
-
|
|
23
|
+
error?: Error,
|
|
23
24
|
isUnhandled = true
|
|
24
25
|
) => {
|
|
25
|
-
if (this.isIgnorable(message)) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
let messageString = '';
|
|
29
26
|
try {
|
|
30
|
-
if (message
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
if (this.isIgnorable(message)) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
let msg = '';
|
|
31
|
+
if (typeof message === 'string') {
|
|
32
|
+
msg = message;
|
|
35
33
|
} else {
|
|
36
|
-
|
|
34
|
+
/*
|
|
35
|
+
* By specification message is always a string
|
|
36
|
+
* this condition covers manual nonuniform window.onerror call
|
|
37
|
+
*/
|
|
38
|
+
msg = serializeWithMetadata(message);
|
|
37
39
|
}
|
|
38
|
-
// eslint-disable-next-line no-empty
|
|
39
|
-
} catch (e) {}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
error.category = 'UnhandledError';
|
|
50
|
-
error.code = error.code ?? 'UnhandledError';
|
|
51
|
-
}
|
|
52
|
-
if (!error.noLog) {
|
|
53
|
-
if (error.name === 'NotFoundError') {
|
|
54
|
-
this.logService.warning({
|
|
55
|
-
category: error.category,
|
|
56
|
-
code: error.code,
|
|
57
|
-
message: error.message,
|
|
58
|
-
data: error.data,
|
|
59
|
-
});
|
|
41
|
+
let err: ExtendedError;
|
|
42
|
+
if (!error || !(error instanceof Error)) {
|
|
43
|
+
const errorMessage = `Message - ${msg}${
|
|
44
|
+
error ? ';Error - ' + serializeWithMetadata(error) : ''
|
|
45
|
+
}`;
|
|
46
|
+
err = new Error(errorMessage);
|
|
47
|
+
err.stack += `\n\tat somewhere (${url}:${line}:${column})`;
|
|
48
|
+
err.code = 'NonUniform';
|
|
60
49
|
} else {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
err = error;
|
|
51
|
+
}
|
|
52
|
+
if (isUnhandled) {
|
|
53
|
+
err.category = 'UnhandledError';
|
|
54
|
+
err.code = err.code ?? 'UnhandledError';
|
|
55
|
+
}
|
|
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
|
+
}
|
|
68
73
|
}
|
|
69
|
-
}
|
|
70
74
|
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
// eslint-disable-next-line no-console
|
|
76
|
+
console.error(err);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
console.error(message);
|
|
80
|
+
// eslint-disable-next-line no-console
|
|
81
|
+
console.error(e);
|
|
82
|
+
}
|
|
73
83
|
};
|
|
74
84
|
|
|
75
|
-
private isIgnorable(message: string
|
|
85
|
+
private isIgnorable(message: string) {
|
|
76
86
|
if (typeof message !== 'string') {
|
|
77
87
|
return false;
|
|
78
88
|
}
|
package/src/log.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { FC } from 'react';
|
|
|
4
4
|
import throttle from 'lodash.throttle';
|
|
5
5
|
import { injectable, inject, Provider, symbolToken } from '@servicetitan/react-ioc';
|
|
6
6
|
import { LogStorage } from './log-storage';
|
|
7
|
+
import { serializeWithMetadata } from './serialize-with-metadata';
|
|
7
8
|
|
|
8
9
|
export interface ArbitaryData extends Record<string, boolean | number | string | Date> {}
|
|
9
10
|
|
|
@@ -76,8 +77,9 @@ export class Log implements ILog {
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
error(entry: LogError): void {
|
|
80
|
+
// eslint-disable-next-line no-console
|
|
81
|
+
console.error(entry);
|
|
79
82
|
return this.errorLogHandler.handle(this.expandError(entry)); // with errorLogHandler throttling
|
|
80
|
-
// return this.store(this.expandError(entry)); // without errorLogHandler throttling
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
private store(entry: EntryComplete) {
|
|
@@ -106,7 +108,7 @@ export class Log implements ILog {
|
|
|
106
108
|
if (entry.error instanceof Error) {
|
|
107
109
|
error = entry.error;
|
|
108
110
|
} else {
|
|
109
|
-
error = new Error(
|
|
111
|
+
error = new Error(serializeWithMetadata(entry.error));
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
const { message, ...rest } = this.expand(LogEntryType.Error, entry);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function serializeWithMetadata(obj: unknown) {
|
|
2
|
+
let result = `Type:${typeof obj}`;
|
|
3
|
+
try {
|
|
4
|
+
if (typeof obj === 'object') {
|
|
5
|
+
result += `|Constructor:${obj?.constructor.name}`;
|
|
6
|
+
if (obj instanceof Event) {
|
|
7
|
+
result += `|EventType:${obj.type}`;
|
|
8
|
+
}
|
|
9
|
+
result += `|Value:${JSON.stringify(obj).substr(0, 100)}`;
|
|
10
|
+
} else if (typeof obj === 'function') {
|
|
11
|
+
result += `|Name:${obj.name}`;
|
|
12
|
+
} else {
|
|
13
|
+
result += `|Value:${JSON.stringify(obj).substr(0, 100)}`;
|
|
14
|
+
}
|
|
15
|
+
} catch (e) {
|
|
16
|
+
result += '|Unable to serialize';
|
|
17
|
+
if (e instanceof Error) {
|
|
18
|
+
result += `: ${e.message.substr(0, 100)}`;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|