topkat-utils 1.2.16 → 1.2.17
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/CHANGELOG.md +4 -0
- package/dist/src/error-utils.d.ts +3 -2
- package/dist/src/error-utils.js +49 -47
- package/dist/src/error-utils.js.map +1 -1
- package/dist/src/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/error-utils.ts +45 -42
- package/src/types.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -16,6 +16,7 @@ export declare class DescriptiveError extends Error {
|
|
|
16
16
|
options: ErrorOptions;
|
|
17
17
|
hasBeenLogged: boolean;
|
|
18
18
|
constructor(msg: string, options?: ErrorOptions);
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
parseError(forCli?: boolean): string[];
|
|
20
|
+
log(): void;
|
|
21
|
+
toString(): string;
|
|
21
22
|
}
|
package/dist/src/error-utils.js
CHANGED
|
@@ -57,8 +57,10 @@ async function tryCatch(callback, onErr = () => { }) {
|
|
|
57
57
|
}
|
|
58
58
|
exports.tryCatch = tryCatch;
|
|
59
59
|
function extraInfosRendererDefault(extraInfos) {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
return [
|
|
61
|
+
'== EXTRA INFOS ==',
|
|
62
|
+
JSON.stringify(extraInfos, null, 2)
|
|
63
|
+
];
|
|
62
64
|
}
|
|
63
65
|
class DescriptiveError extends Error {
|
|
64
66
|
constructor(msg, options = {}) {
|
|
@@ -80,58 +82,58 @@ class DescriptiveError extends Error {
|
|
|
80
82
|
const { onError = () => { } } = (0, config_1.configFn)();
|
|
81
83
|
onError(msg, options);
|
|
82
84
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
logErr(noStackTrace, err.extraInfos);
|
|
111
|
-
}
|
|
85
|
+
parseError(forCli = false) {
|
|
86
|
+
const errorLogs = [];
|
|
87
|
+
const _a = this.options, { err, doNotThrow = false, noStackTrace = false, ressource, extraInfosRenderer = extraInfosRendererDefault, notifyOnSlackChannel = false, originalMessage } = _a, extraInfosRaw = __rest(_a, ["err", "doNotThrow", "noStackTrace", "ressource", "extraInfosRenderer", "notifyOnSlackChannel", "originalMessage"]);
|
|
88
|
+
let { code } = this.options;
|
|
89
|
+
const extraInfos = Object.assign(Object.assign({}, extraInfosRaw), (this.options.extraInfos || {}));
|
|
90
|
+
this.code = code || 500;
|
|
91
|
+
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !(0, isset_1.isset)(this.options.code)))
|
|
92
|
+
delete this.code;
|
|
93
|
+
if (!(0, isset_1.isset)(extraInfos.value) && this.options.hasOwnProperty('value'))
|
|
94
|
+
extraInfos.value = 'undefined';
|
|
95
|
+
if (!(0, isset_1.isset)(extraInfos.gotValue) && this.options.hasOwnProperty('gotValue'))
|
|
96
|
+
extraInfos.gotValue = 'undefined';
|
|
97
|
+
if ((0, isset_1.isset)(ressource)) {
|
|
98
|
+
code = 404;
|
|
99
|
+
if (this.msg === '404')
|
|
100
|
+
this.msg = `Ressource ${ressource} not found`;
|
|
101
|
+
extraInfos.ressource = ressource;
|
|
102
|
+
}
|
|
103
|
+
errorLogs.push(this.msg || this.message);
|
|
104
|
+
if (Object.keys(extraInfos).length > 0)
|
|
105
|
+
extraInfosRenderer(extraInfos);
|
|
106
|
+
if (err) {
|
|
107
|
+
errorLogs.push('== ORIGINAL ERROR ==');
|
|
108
|
+
if (typeof err.parseError === 'function') {
|
|
109
|
+
err.hasBeenLogged = false;
|
|
110
|
+
const logFromOtherErr = err.parseError(forCli);
|
|
111
|
+
errorLogs.push(...logFromOtherErr);
|
|
112
112
|
}
|
|
113
113
|
else {
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
errorLogs.push(err.toString());
|
|
115
|
+
if (!noStackTrace && err.stack)
|
|
116
|
+
errorLogs.push(err.stack);
|
|
117
|
+
if (err.extraInfos)
|
|
118
|
+
errorLogs.push(err.extraInfos);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
if (!noStackTrace) {
|
|
123
|
+
const stackTranceClean = (0, clean_stack_trace_1.cleanStackTrace)(extraInfosRaw.stack || this.stack);
|
|
124
|
+
errorLogs.push(forCli ? logger_utils_1.C.dim(stackTranceClean) : stackTranceClean);
|
|
116
125
|
}
|
|
117
|
-
this.code = code || 500;
|
|
118
|
-
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !(0, isset_1.isset)(this.options.code)))
|
|
119
|
-
delete this.code;
|
|
120
|
-
this.errorDescription = Object.assign({ msg: this.msg, code,
|
|
121
|
-
ressource }, extraInfos);
|
|
122
126
|
}
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
return errorLogs;
|
|
128
|
+
}
|
|
129
|
+
log() {
|
|
130
|
+
if (!this.hasBeenLogged)
|
|
131
|
+
this.parseError().forEach(errLine => logger_utils_1.C.error(false, errLine));
|
|
132
|
+
this.hasBeenLogged = true;
|
|
125
133
|
}
|
|
126
134
|
toString() {
|
|
127
|
-
return this.
|
|
135
|
+
return this.parseError().join('\n');
|
|
128
136
|
}
|
|
129
137
|
}
|
|
130
138
|
exports.DescriptiveError = DescriptiveError;
|
|
131
|
-
function logErr(noStackTrace, ...params) {
|
|
132
|
-
if (noStackTrace)
|
|
133
|
-
logger_utils_1.C.error(false, ...params);
|
|
134
|
-
else
|
|
135
|
-
logger_utils_1.C.error(...params);
|
|
136
|
-
}
|
|
137
139
|
//# sourceMappingURL=error-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|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AAI,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,gBAAC,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;QACtF,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;IAC7B,CAAC;IACD,QAAQ;QACJ,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvC,CAAC;CACJ;AAxED,4CAwEC"}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export declare type ErrorOptions = {
|
|
|
9
9
|
code?: number;
|
|
10
10
|
doNotDisplayCode?: boolean;
|
|
11
11
|
notifyOnSlackChannel?: boolean;
|
|
12
|
-
extraInfosRenderer?: (extraInfosObj: ObjectGeneric) =>
|
|
12
|
+
extraInfosRenderer?: (extraInfosObj: ObjectGeneric) => string[];
|
|
13
13
|
doNotWaitOneFrameForLog?: boolean;
|
|
14
14
|
noStackTrace?: boolean;
|
|
15
15
|
[k: string]: any;
|
package/package.json
CHANGED
package/src/error-utils.ts
CHANGED
|
@@ -44,8 +44,10 @@ export async function tryCatch(callback: Function, onErr: Function = () => { })
|
|
|
44
44
|
|
|
45
45
|
|
|
46
46
|
function extraInfosRendererDefault(extraInfos) {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
return [
|
|
48
|
+
'== EXTRA INFOS ==',
|
|
49
|
+
JSON.stringify(extraInfos, null, 2)
|
|
50
|
+
]
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
export class DescriptiveError extends Error {
|
|
@@ -71,52 +73,53 @@ export class DescriptiveError extends Error {
|
|
|
71
73
|
const { onError = () => { } } = configFn()
|
|
72
74
|
onError(msg, options)
|
|
73
75
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!isset(extraInfos.gotValue) && this.options.hasOwnProperty('gotValue')) extraInfos.gotValue = 'undefined'
|
|
82
|
-
|
|
83
|
-
if (isset(ressource)) {
|
|
84
|
-
code = 404
|
|
85
|
-
if (this.msg === '404') this.msg = `Ressource ${ressource} not found`
|
|
86
|
-
extraInfos.ressource = ressource
|
|
87
|
-
}
|
|
76
|
+
parseError(forCli = false) {
|
|
77
|
+
|
|
78
|
+
const errorLogs: string[] = []
|
|
79
|
+
|
|
80
|
+
const { err, doNotThrow = false, noStackTrace = false, ressource, extraInfosRenderer = extraInfosRendererDefault, notifyOnSlackChannel = false, originalMessage, ...extraInfosRaw } = this.options
|
|
81
|
+
let { code } = this.options
|
|
82
|
+
const extraInfos = { ...extraInfosRaw, ...(this.options.extraInfos || {}) }
|
|
88
83
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
84
|
+
this.code = code || 500
|
|
85
|
+
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !isset(this.options.code))) delete this.code
|
|
86
|
+
|
|
87
|
+
if (!isset(extraInfos.value) && this.options.hasOwnProperty('value')) extraInfos.value = 'undefined'
|
|
88
|
+
if (!isset(extraInfos.gotValue) && this.options.hasOwnProperty('gotValue')) extraInfos.gotValue = 'undefined'
|
|
89
|
+
|
|
90
|
+
if (isset(ressource)) {
|
|
91
|
+
code = 404
|
|
92
|
+
if (this.msg === '404') this.msg = `Ressource ${ressource} not found`
|
|
93
|
+
extraInfos.ressource = ressource
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
errorLogs.push(this.msg || this.message)
|
|
97
|
+
if (Object.keys(extraInfos).length > 0) extraInfosRenderer(extraInfos)
|
|
98
|
+
if (err) {
|
|
99
|
+
errorLogs.push('== ORIGINAL ERROR ==')
|
|
100
|
+
if (typeof err.parseError === 'function') {
|
|
101
|
+
err.hasBeenLogged = false
|
|
102
|
+
const logFromOtherErr = err.parseError(forCli)
|
|
103
|
+
errorLogs.push(...logFromOtherErr)
|
|
100
104
|
} else {
|
|
101
|
-
|
|
105
|
+
errorLogs.push(err.toString())
|
|
106
|
+
if (!noStackTrace && err.stack) errorLogs.push(err.stack)
|
|
107
|
+
if (err.extraInfos) errorLogs.push(err.extraInfos)
|
|
102
108
|
}
|
|
103
|
-
|
|
104
|
-
if (
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
code,
|
|
108
|
-
ressource,
|
|
109
|
-
...extraInfos,
|
|
109
|
+
} else {
|
|
110
|
+
if (!noStackTrace) {
|
|
111
|
+
const stackTranceClean = cleanStackTrace(extraInfosRaw.stack || this.stack)
|
|
112
|
+
errorLogs.push(forCli ? C.dim(stackTranceClean) : stackTranceClean)
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
|
-
|
|
115
|
+
|
|
116
|
+
return errorLogs
|
|
117
|
+
}
|
|
118
|
+
log() {
|
|
119
|
+
if (!this.hasBeenLogged) this.parseError().forEach(errLine => C.error(false, errLine))
|
|
120
|
+
this.hasBeenLogged = true
|
|
113
121
|
}
|
|
114
122
|
toString() {
|
|
115
|
-
return this.
|
|
123
|
+
return this.parseError().join('\n')
|
|
116
124
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function logErr(noStackTrace: boolean, ...params: any[]) {
|
|
120
|
-
if (noStackTrace) C.error(false, ...params)
|
|
121
|
-
else C.error(...params)
|
|
122
125
|
}
|
package/src/types.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type ErrorOptions = {
|
|
|
11
11
|
code?: number
|
|
12
12
|
doNotDisplayCode?: boolean
|
|
13
13
|
notifyOnSlackChannel?: boolean
|
|
14
|
-
extraInfosRenderer?: (extraInfosObj: ObjectGeneric) =>
|
|
14
|
+
extraInfosRenderer?: (extraInfosObj: ObjectGeneric) => string[]
|
|
15
15
|
doNotWaitOneFrameForLog?: boolean
|
|
16
16
|
noStackTrace?: boolean
|
|
17
17
|
[k: string]: any
|