topkat-utils 1.3.13 → 1.3.14
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/src/error-utils.d.ts +1 -4
- package/dist/src/error-utils.js +12 -15
- package/dist/src/error-utils.js.map +1 -1
- package/package.json +1 -1
- package/src/error-utils.ts +11 -15
|
@@ -16,7 +16,6 @@ export declare class DescriptiveError<ExpectedOriginalError = any> extends Error
|
|
|
16
16
|
id: string;
|
|
17
17
|
/** Http error code if any */
|
|
18
18
|
code: number;
|
|
19
|
-
msg: string;
|
|
20
19
|
message: string;
|
|
21
20
|
/** The parent error if any */
|
|
22
21
|
originalError?: Error | Record<string, any> | DescriptiveError;
|
|
@@ -28,8 +27,6 @@ export declare class DescriptiveError<ExpectedOriginalError = any> extends Error
|
|
|
28
27
|
id: string;
|
|
29
28
|
/** Http code. Eg: 404, 403... */
|
|
30
29
|
code?: number;
|
|
31
|
-
msg: string;
|
|
32
|
-
/** Alias since .msg is not always obvious to find */
|
|
33
30
|
message: string;
|
|
34
31
|
options: ErrorOptions;
|
|
35
32
|
/** Logging of the error is async, unless disabled, so that it wait one frame to allow to log it manually */
|
|
@@ -37,7 +34,7 @@ export declare class DescriptiveError<ExpectedOriginalError = any> extends Error
|
|
|
37
34
|
isAxiosError: boolean;
|
|
38
35
|
doNotLog: boolean;
|
|
39
36
|
logs: string[];
|
|
40
|
-
constructor(
|
|
37
|
+
constructor(message: string, options?: ErrorOptions);
|
|
41
38
|
/** Compute extraInfos and parse options */
|
|
42
39
|
parseError(forCli?: boolean): string[];
|
|
43
40
|
log(): void;
|
package/dist/src/error-utils.js
CHANGED
|
@@ -57,7 +57,7 @@ exports.failSafe = tryCatch; // ALIAS
|
|
|
57
57
|
function extraInfosRendererDefault(extraInfos) {
|
|
58
58
|
return [
|
|
59
59
|
'== EXTRA INFOS ==',
|
|
60
|
-
(0, remove_circular_json_stringify_1.removeCircularJSONstringify)({ ...extraInfos,
|
|
60
|
+
(0, remove_circular_json_stringify_1.removeCircularJSONstringify)({ ...extraInfos, message: undefined, stack: undefined, originalError: undefined, hasBeenLogged: undefined, logs: undefined }, 2)
|
|
61
61
|
];
|
|
62
62
|
}
|
|
63
63
|
class DescriptiveError extends Error {
|
|
@@ -69,8 +69,6 @@ class DescriptiveError extends Error {
|
|
|
69
69
|
id = (0, string_utils_1.generateToken)(24, true);
|
|
70
70
|
/** Http code. Eg: 404, 403... */
|
|
71
71
|
code;
|
|
72
|
-
msg;
|
|
73
|
-
/** Alias since .msg is not always obvious to find */
|
|
74
72
|
message;
|
|
75
73
|
options;
|
|
76
74
|
/** Logging of the error is async, unless disabled, so that it wait one frame to allow to log it manually */
|
|
@@ -78,11 +76,10 @@ class DescriptiveError extends Error {
|
|
|
78
76
|
isAxiosError = false;
|
|
79
77
|
doNotLog = false; // just an alias for the above, actually using this one can be more readable in some situations
|
|
80
78
|
logs = [];
|
|
81
|
-
constructor(
|
|
82
|
-
super(
|
|
79
|
+
constructor(message, options = {}) {
|
|
80
|
+
super(message);
|
|
83
81
|
delete options.errMsgId;
|
|
84
|
-
this.
|
|
85
|
-
this.message = msg;
|
|
82
|
+
this.message = message;
|
|
86
83
|
this.isAxiosError = (options?.err?.stack || options.stack)?.startsWith('Axios') || false;
|
|
87
84
|
const { doNotWaitOneFrameForLog = options.code === 500, ...optionsClean } = options;
|
|
88
85
|
this.options = optionsClean;
|
|
@@ -106,7 +103,7 @@ class DescriptiveError extends Error {
|
|
|
106
103
|
});
|
|
107
104
|
const { onError } = (0, config_1.configFn)();
|
|
108
105
|
if (typeof onError === 'function')
|
|
109
|
-
onError(
|
|
106
|
+
onError(message, options);
|
|
110
107
|
}
|
|
111
108
|
/** Compute extraInfos and parse options */
|
|
112
109
|
parseError(forCli = false) {
|
|
@@ -133,8 +130,8 @@ class DescriptiveError extends Error {
|
|
|
133
130
|
}
|
|
134
131
|
if ((0, isset_1.isset)(ressource)) {
|
|
135
132
|
code = 404;
|
|
136
|
-
if (this.
|
|
137
|
-
this.
|
|
133
|
+
if (this.message === '404')
|
|
134
|
+
this.message = `Ressource ${ressource} not found`;
|
|
138
135
|
extraInfos.ressource = ressource;
|
|
139
136
|
}
|
|
140
137
|
errorLogs.push(computeErrorMessage(this));
|
|
@@ -147,13 +144,14 @@ class DescriptiveError extends Error {
|
|
|
147
144
|
this.originalError = err;
|
|
148
145
|
errorLogs.push('== ORIGINAL ERROR ==');
|
|
149
146
|
errorLogs.push(computeErrorMessage(err));
|
|
150
|
-
if (typeof err.parseError === 'function') {
|
|
147
|
+
if (typeof err.parseError === 'function' || Array.isArray(err?.logs)) {
|
|
151
148
|
// The catched error is a DescriptiveError so from
|
|
152
149
|
// there we prevent further logs/ outpus from error
|
|
153
150
|
err.hasBeenLogged = true; // this will be logged in the child error so we dont want it to be logged twice
|
|
154
151
|
err.doNotLog = true;
|
|
155
|
-
const logFromOtherErr = err
|
|
156
|
-
|
|
152
|
+
const logFromOtherErr = err?.logs || err?.parseError?.(forCli) || [];
|
|
153
|
+
const [, ...errToLog] = logFromOtherErr;
|
|
154
|
+
errorLogs.push(...errToLog);
|
|
157
155
|
}
|
|
158
156
|
else {
|
|
159
157
|
errorLogs.push((0, remove_circular_json_stringify_1.removeCircularJSONstringify)({ ...err, hasBeenLogged: undefined }));
|
|
@@ -175,8 +173,7 @@ class DescriptiveError extends Error {
|
|
|
175
173
|
delete this.code;
|
|
176
174
|
this.errorDescription = {
|
|
177
175
|
id: this.id,
|
|
178
|
-
|
|
179
|
-
message: this.msg,
|
|
176
|
+
message: this.message,
|
|
180
177
|
code,
|
|
181
178
|
ressource,
|
|
182
179
|
originalError: err,
|
|
@@ -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,2DAAqD;AACrD,iDAAkC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AC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;AACtE,CAAC"}
|
package/package.json
CHANGED
package/src/error-utils.ts
CHANGED
|
@@ -51,7 +51,7 @@ export const failSafe = tryCatch // ALIAS
|
|
|
51
51
|
function extraInfosRendererDefault(extraInfos) {
|
|
52
52
|
return [
|
|
53
53
|
'== EXTRA INFOS ==',
|
|
54
|
-
removeCircularJSONstringify({ ...extraInfos,
|
|
54
|
+
removeCircularJSONstringify({ ...extraInfos, message: undefined, stack: undefined, originalError: undefined, hasBeenLogged: undefined, logs: undefined }, 2)
|
|
55
55
|
]
|
|
56
56
|
}
|
|
57
57
|
|
|
@@ -64,7 +64,6 @@ export class DescriptiveError<ExpectedOriginalError = any> extends Error {
|
|
|
64
64
|
id: string
|
|
65
65
|
/** Http error code if any */
|
|
66
66
|
code: number
|
|
67
|
-
msg: string
|
|
68
67
|
message: string
|
|
69
68
|
/** The parent error if any */
|
|
70
69
|
originalError?: Error | Record<string, any> | DescriptiveError
|
|
@@ -76,8 +75,6 @@ export class DescriptiveError<ExpectedOriginalError = any> extends Error {
|
|
|
76
75
|
id: string = generateToken(24, true)
|
|
77
76
|
/** Http code. Eg: 404, 403... */
|
|
78
77
|
code?: number
|
|
79
|
-
msg: string
|
|
80
|
-
/** Alias since .msg is not always obvious to find */
|
|
81
78
|
message: string
|
|
82
79
|
options: ErrorOptions
|
|
83
80
|
/** Logging of the error is async, unless disabled, so that it wait one frame to allow to log it manually */
|
|
@@ -86,11 +83,10 @@ export class DescriptiveError<ExpectedOriginalError = any> extends Error {
|
|
|
86
83
|
doNotLog = false // just an alias for the above, actually using this one can be more readable in some situations
|
|
87
84
|
logs: string[] = []
|
|
88
85
|
|
|
89
|
-
constructor(
|
|
90
|
-
super(
|
|
86
|
+
constructor(message: string, options: ErrorOptions = {}) {
|
|
87
|
+
super(message)
|
|
91
88
|
delete options.errMsgId
|
|
92
|
-
this.
|
|
93
|
-
this.message = msg
|
|
89
|
+
this.message = message
|
|
94
90
|
|
|
95
91
|
this.isAxiosError = (options?.err?.stack || options.stack)?.startsWith('Axios') || false
|
|
96
92
|
|
|
@@ -115,7 +111,7 @@ export class DescriptiveError<ExpectedOriginalError = any> extends Error {
|
|
|
115
111
|
})
|
|
116
112
|
|
|
117
113
|
const { onError } = configFn()
|
|
118
|
-
if (typeof onError === 'function') onError(
|
|
114
|
+
if (typeof onError === 'function') onError(message, options)
|
|
119
115
|
|
|
120
116
|
}
|
|
121
117
|
/** Compute extraInfos and parse options */
|
|
@@ -148,7 +144,7 @@ export class DescriptiveError<ExpectedOriginalError = any> extends Error {
|
|
|
148
144
|
|
|
149
145
|
if (isset(ressource)) {
|
|
150
146
|
code = 404
|
|
151
|
-
if (this.
|
|
147
|
+
if (this.message === '404') this.message = `Ressource ${ressource} not found`
|
|
152
148
|
extraInfos.ressource = ressource
|
|
153
149
|
}
|
|
154
150
|
|
|
@@ -164,13 +160,14 @@ export class DescriptiveError<ExpectedOriginalError = any> extends Error {
|
|
|
164
160
|
this.originalError = err
|
|
165
161
|
errorLogs.push('== ORIGINAL ERROR ==')
|
|
166
162
|
errorLogs.push(computeErrorMessage(err))
|
|
167
|
-
if (typeof err.parseError === 'function') {
|
|
163
|
+
if (typeof err.parseError === 'function' || Array.isArray(err?.logs)) {
|
|
168
164
|
// The catched error is a DescriptiveError so from
|
|
169
165
|
// there we prevent further logs/ outpus from error
|
|
170
166
|
err.hasBeenLogged = true // this will be logged in the child error so we dont want it to be logged twice
|
|
171
167
|
err.doNotLog = true
|
|
172
|
-
const logFromOtherErr = err
|
|
173
|
-
|
|
168
|
+
const logFromOtherErr = err?.logs || err?.parseError?.(forCli) || []
|
|
169
|
+
const [, ...errToLog] = logFromOtherErr
|
|
170
|
+
errorLogs.push(...errToLog)
|
|
174
171
|
} else {
|
|
175
172
|
errorLogs.push(removeCircularJSONstringify({ ...err, hasBeenLogged: undefined }))
|
|
176
173
|
if (!noStackTrace && err.stack) errorLogs.push(cleanStackTrace(err.stack))
|
|
@@ -188,8 +185,7 @@ export class DescriptiveError<ExpectedOriginalError = any> extends Error {
|
|
|
188
185
|
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !isset(this.options.code))) delete this.code
|
|
189
186
|
this.errorDescription = {
|
|
190
187
|
id: this.id,
|
|
191
|
-
|
|
192
|
-
message: this.msg,
|
|
188
|
+
message: this.message,
|
|
193
189
|
code,
|
|
194
190
|
ressource,
|
|
195
191
|
originalError: err,
|