topkat-utils 1.2.17 → 1.2.19
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/.eslintrc +47 -0
- package/dist/src/error-utils.d.ts +2 -1
- package/dist/src/error-utils.js +18 -6
- package/dist/src/error-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/error-utils.ts +29 -9
package/.eslintrc
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"es6": true,
|
|
4
|
+
"node": true,
|
|
5
|
+
"mocha": true,
|
|
6
|
+
"browser": true
|
|
7
|
+
},
|
|
8
|
+
"extends": [
|
|
9
|
+
"eslint:recommended"
|
|
10
|
+
],
|
|
11
|
+
"parserOptions": {
|
|
12
|
+
"ecmaVersion": 2018,
|
|
13
|
+
"sourceType": "module",
|
|
14
|
+
"allowImportExportEverywhere": true
|
|
15
|
+
},
|
|
16
|
+
"rules": {
|
|
17
|
+
"no-inner-declarations": "off",
|
|
18
|
+
"no-console": "warn",
|
|
19
|
+
"no-unused-vars": "warn",
|
|
20
|
+
"no-global-assign": "warn",
|
|
21
|
+
"require-atomic-updates": "off",
|
|
22
|
+
"no-prototype-builtins": "off",
|
|
23
|
+
"no-extra-semi": "error",
|
|
24
|
+
"linebreak-style": [
|
|
25
|
+
"error",
|
|
26
|
+
"unix"
|
|
27
|
+
],
|
|
28
|
+
"quotes": [
|
|
29
|
+
"error",
|
|
30
|
+
"single",
|
|
31
|
+
{
|
|
32
|
+
"allowTemplateLiterals": true
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
"semi": [
|
|
36
|
+
"error",
|
|
37
|
+
"never"
|
|
38
|
+
],
|
|
39
|
+
"brace-style": [
|
|
40
|
+
1,
|
|
41
|
+
"1tbs",
|
|
42
|
+
{
|
|
43
|
+
"allowSingleLine": true
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -15,8 +15,9 @@ export declare class DescriptiveError extends Error {
|
|
|
15
15
|
msg: string;
|
|
16
16
|
options: ErrorOptions;
|
|
17
17
|
hasBeenLogged: boolean;
|
|
18
|
+
logs: string[];
|
|
18
19
|
constructor(msg: string, options?: ErrorOptions);
|
|
19
|
-
parseError(forCli?: boolean):
|
|
20
|
+
parseError(forCli?: boolean): void;
|
|
20
21
|
log(): void;
|
|
21
22
|
toString(): string;
|
|
22
23
|
}
|
package/dist/src/error-utils.js
CHANGED
|
@@ -65,6 +65,8 @@ function extraInfosRendererDefault(extraInfos) {
|
|
|
65
65
|
class DescriptiveError extends Error {
|
|
66
66
|
constructor(msg, options = {}) {
|
|
67
67
|
super(msg);
|
|
68
|
+
this.hasBeenLogged = false;
|
|
69
|
+
this.logs = [];
|
|
68
70
|
delete options.errMsgId;
|
|
69
71
|
this.msg = msg;
|
|
70
72
|
const { doNotWaitOneFrameForLog = false } = options, optionsClean = __rest(options, ["doNotWaitOneFrameForLog"]);
|
|
@@ -81,6 +83,7 @@ class DescriptiveError extends Error {
|
|
|
81
83
|
});
|
|
82
84
|
const { onError = () => { } } = (0, config_1.configFn)();
|
|
83
85
|
onError(msg, options);
|
|
86
|
+
this.parseError();
|
|
84
87
|
}
|
|
85
88
|
parseError(forCli = false) {
|
|
86
89
|
const errorLogs = [];
|
|
@@ -101,8 +104,9 @@ class DescriptiveError extends Error {
|
|
|
101
104
|
extraInfos.ressource = ressource;
|
|
102
105
|
}
|
|
103
106
|
errorLogs.push(this.msg || this.message);
|
|
104
|
-
if (Object.keys(extraInfos).length > 0)
|
|
105
|
-
extraInfosRenderer(extraInfos);
|
|
107
|
+
if (Object.keys(extraInfos).length > 0) {
|
|
108
|
+
errorLogs.push(...extraInfosRenderer(extraInfos));
|
|
109
|
+
}
|
|
106
110
|
if (err) {
|
|
107
111
|
errorLogs.push('== ORIGINAL ERROR ==');
|
|
108
112
|
if (typeof err.parseError === 'function') {
|
|
@@ -113,7 +117,7 @@ class DescriptiveError extends Error {
|
|
|
113
117
|
else {
|
|
114
118
|
errorLogs.push(err.toString());
|
|
115
119
|
if (!noStackTrace && err.stack)
|
|
116
|
-
errorLogs.push(err.stack);
|
|
120
|
+
errorLogs.push((0, clean_stack_trace_1.cleanStackTrace)(err.stack));
|
|
117
121
|
if (err.extraInfos)
|
|
118
122
|
errorLogs.push(err.extraInfos);
|
|
119
123
|
}
|
|
@@ -124,15 +128,23 @@ class DescriptiveError extends Error {
|
|
|
124
128
|
errorLogs.push(forCli ? logger_utils_1.C.dim(stackTranceClean) : stackTranceClean);
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
|
-
|
|
131
|
+
// THIS is used to access error as object
|
|
132
|
+
this.code = code || 500;
|
|
133
|
+
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !(0, isset_1.isset)(this.options.code)))
|
|
134
|
+
delete this.code;
|
|
135
|
+
this.errorDescription = Object.assign({ msg: this.msg, code,
|
|
136
|
+
ressource }, extraInfos);
|
|
137
|
+
if (err)
|
|
138
|
+
this.errorDescription.originalError = `${err.code ? err.code + ': ' : ''}${err.message || err.msg || err.toString()}`;
|
|
139
|
+
this.logs = errorLogs;
|
|
128
140
|
}
|
|
129
141
|
log() {
|
|
130
142
|
if (!this.hasBeenLogged)
|
|
131
|
-
this.
|
|
143
|
+
this.logs.forEach(errLine => logger_utils_1.C.error(false, errLine));
|
|
132
144
|
this.hasBeenLogged = true;
|
|
133
145
|
}
|
|
134
146
|
toString() {
|
|
135
|
-
return this.
|
|
147
|
+
return this.logs.join('\n');
|
|
136
148
|
}
|
|
137
149
|
}
|
|
138
150
|
exports.DescriptiveError = DescriptiveError;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-utils.js","sourceRoot":"","sources":["../../src/error-utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,0CAA0C;AAC1C,cAAc;AACd,0CAA0C;AAC1C,qCAAmC;AACnC,mCAA+B;AAC/B,yCAAoC;AAEpC,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OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,IAAA,aAAK,EAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC,IAAI,CAAA;QACzH,IAAI,CAAC,gBAAgB,mBACjB,GAAG,EAAE,IAAI,CAAC,GAAG,EACb,IAAI;YACJ,SAAS,IACN,UAAU,CAChB,CAAA;QACD,IAAI,GAAG;YAAE,IAAI,CAAC,gBAAgB,CAAC,aAAa,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAA;QAE9H,IAAI,CAAC,IAAI,GAAG,SAAS,CAAA;IACzB,CAAC;IACD,GAAG;QACC,IAAI,CAAC,IAAI,CAAC,aAAa;YAAE,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,gBAAC,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;QAC9E,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;IAC7B,CAAC;IACD,QAAQ;QACJ,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/B,CAAC;CACJ;AA9FD,4CA8FC"}
|
package/package.json
CHANGED
package/src/error-utils.ts
CHANGED
|
@@ -41,8 +41,6 @@ export async function tryCatch(callback: Function, onErr: Function = () => { })
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
44
|
function extraInfosRendererDefault(extraInfos) {
|
|
47
45
|
return [
|
|
48
46
|
'== EXTRA INFOS ==',
|
|
@@ -55,7 +53,8 @@ export class DescriptiveError extends Error {
|
|
|
55
53
|
code: number
|
|
56
54
|
msg: string
|
|
57
55
|
options: ErrorOptions
|
|
58
|
-
hasBeenLogged: boolean
|
|
56
|
+
hasBeenLogged: boolean = false
|
|
57
|
+
logs: string[] = []
|
|
59
58
|
|
|
60
59
|
constructor(msg: string, options: ErrorOptions = {}) {
|
|
61
60
|
super(msg)
|
|
@@ -72,6 +71,8 @@ export class DescriptiveError extends Error {
|
|
|
72
71
|
|
|
73
72
|
const { onError = () => { } } = configFn()
|
|
74
73
|
onError(msg, options)
|
|
74
|
+
|
|
75
|
+
this.parseError()
|
|
75
76
|
}
|
|
76
77
|
parseError(forCli = false) {
|
|
77
78
|
|
|
@@ -79,7 +80,11 @@ export class DescriptiveError extends Error {
|
|
|
79
80
|
|
|
80
81
|
const { err, doNotThrow = false, noStackTrace = false, ressource, extraInfosRenderer = extraInfosRendererDefault, notifyOnSlackChannel = false, originalMessage, ...extraInfosRaw } = this.options
|
|
81
82
|
let { code } = this.options
|
|
82
|
-
const extraInfos = {
|
|
83
|
+
const extraInfos = {
|
|
84
|
+
...extraInfosRaw,
|
|
85
|
+
// additionnal extra info passed from parent error
|
|
86
|
+
...(this.options.extraInfos || {}),
|
|
87
|
+
}
|
|
83
88
|
|
|
84
89
|
this.code = code || 500
|
|
85
90
|
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !isset(this.options.code))) delete this.code
|
|
@@ -94,7 +99,11 @@ export class DescriptiveError extends Error {
|
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
errorLogs.push(this.msg || this.message)
|
|
97
|
-
|
|
102
|
+
|
|
103
|
+
if (Object.keys(extraInfos).length > 0) {
|
|
104
|
+
errorLogs.push(...extraInfosRenderer(extraInfos))
|
|
105
|
+
}
|
|
106
|
+
|
|
98
107
|
if (err) {
|
|
99
108
|
errorLogs.push('== ORIGINAL ERROR ==')
|
|
100
109
|
if (typeof err.parseError === 'function') {
|
|
@@ -103,7 +112,7 @@ export class DescriptiveError extends Error {
|
|
|
103
112
|
errorLogs.push(...logFromOtherErr)
|
|
104
113
|
} else {
|
|
105
114
|
errorLogs.push(err.toString())
|
|
106
|
-
if (!noStackTrace && err.stack) errorLogs.push(err.stack)
|
|
115
|
+
if (!noStackTrace && err.stack) errorLogs.push(cleanStackTrace(err.stack))
|
|
107
116
|
if (err.extraInfos) errorLogs.push(err.extraInfos)
|
|
108
117
|
}
|
|
109
118
|
} else {
|
|
@@ -113,13 +122,24 @@ export class DescriptiveError extends Error {
|
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
// THIS is used to access error as object
|
|
126
|
+
this.code = code || 500
|
|
127
|
+
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !isset(this.options.code))) delete this.code
|
|
128
|
+
this.errorDescription = {
|
|
129
|
+
msg: this.msg,
|
|
130
|
+
code,
|
|
131
|
+
ressource,
|
|
132
|
+
...extraInfos,
|
|
133
|
+
}
|
|
134
|
+
if (err) this.errorDescription.originalError = `${err.code ? err.code + ': ' : ''}${err.message || err.msg || err.toString()}`
|
|
135
|
+
|
|
136
|
+
this.logs = errorLogs
|
|
117
137
|
}
|
|
118
138
|
log() {
|
|
119
|
-
if (!this.hasBeenLogged) this.
|
|
139
|
+
if (!this.hasBeenLogged) this.logs.forEach(errLine => C.error(false, errLine))
|
|
120
140
|
this.hasBeenLogged = true
|
|
121
141
|
}
|
|
122
142
|
toString() {
|
|
123
|
-
return this.
|
|
143
|
+
return this.logs.join('\n')
|
|
124
144
|
}
|
|
125
145
|
}
|