topkat-utils 1.2.72 → 1.2.73
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.
|
@@ -12,11 +12,17 @@ export declare const failSafe: typeof tryCatch;
|
|
|
12
12
|
export declare class DescriptiveError extends Error {
|
|
13
13
|
/** Full error infos, extra infos + message and code...etc as object */
|
|
14
14
|
errorDescription: {
|
|
15
|
+
code: number;
|
|
16
|
+
msg: string;
|
|
17
|
+
message: string;
|
|
18
|
+
originalError?: string;
|
|
15
19
|
[k: string]: any;
|
|
16
20
|
};
|
|
17
21
|
/** Http code. Eg: 404, 403... */
|
|
18
22
|
code?: number;
|
|
19
23
|
msg: string;
|
|
24
|
+
/** Alias since .msg is not always obvious to find */
|
|
25
|
+
message: string;
|
|
20
26
|
options: ErrorOptions;
|
|
21
27
|
/** Logging of the error is async, unless disabled, so that it wait one frame to allow to log it manually */
|
|
22
28
|
hasBeenLogged: boolean;
|
package/dist/src/error-utils.js
CHANGED
|
@@ -20,6 +20,7 @@ const isset_1 = require("./isset");
|
|
|
20
20
|
const is_empty_1 = require("./is-empty");
|
|
21
21
|
const clean_stack_trace_1 = require("./clean-stack-trace");
|
|
22
22
|
const logger_utils_1 = require("./logger-utils");
|
|
23
|
+
const remove_circular_json_stringify_1 = require("./remove-circular-json-stringify");
|
|
23
24
|
function errIfNotSet(objOfVarNamesWithValues) { return errXXXIfNotSet(422, false, objOfVarNamesWithValues); }
|
|
24
25
|
exports.errIfNotSet = errIfNotSet;
|
|
25
26
|
function err500IfNotSet(objOfVarNamesWithValues) { return errXXXIfNotSet(500, false, objOfVarNamesWithValues); }
|
|
@@ -65,7 +66,7 @@ exports.failSafe = tryCatch; // ALIAS
|
|
|
65
66
|
function extraInfosRendererDefault(extraInfos) {
|
|
66
67
|
return [
|
|
67
68
|
'== EXTRA INFOS ==',
|
|
68
|
-
|
|
69
|
+
(0, remove_circular_json_stringify_1.removeCircularJSONstringify)(extraInfos, 2)
|
|
69
70
|
];
|
|
70
71
|
}
|
|
71
72
|
class DescriptiveError extends Error {
|
|
@@ -78,6 +79,7 @@ class DescriptiveError extends Error {
|
|
|
78
79
|
this.logs = [];
|
|
79
80
|
delete options.errMsgId;
|
|
80
81
|
this.msg = msg;
|
|
82
|
+
this.message = msg;
|
|
81
83
|
const { doNotWaitOneFrameForLog = false } = options, optionsClean = __rest(options, ["doNotWaitOneFrameForLog"]);
|
|
82
84
|
this.options = optionsClean;
|
|
83
85
|
if (optionsClean.err)
|
|
@@ -93,13 +95,16 @@ class DescriptiveError extends Error {
|
|
|
93
95
|
if (!this.hasBeenLogged)
|
|
94
96
|
this.log();
|
|
95
97
|
});
|
|
96
|
-
const { onError
|
|
97
|
-
|
|
98
|
+
const { onError } = (0, config_1.configFn)();
|
|
99
|
+
if (typeof onError === 'function')
|
|
100
|
+
onError(msg, options);
|
|
98
101
|
}
|
|
99
102
|
/** Compute extraInfos and parse options */
|
|
100
103
|
parseError(forCli = false) {
|
|
104
|
+
var _a;
|
|
105
|
+
var _b;
|
|
101
106
|
const errorLogs = [];
|
|
102
|
-
const
|
|
107
|
+
const _c = this.options, { err, noStackTrace = false, ressource, extraInfosRenderer = extraInfosRendererDefault } = _c, extraInfosRaw = __rest(_c, ["err", "noStackTrace", "ressource", "extraInfosRenderer"]);
|
|
103
108
|
let { code } = this.options;
|
|
104
109
|
const extraInfos = Object.assign(Object.assign({}, extraInfosRaw), (this.options.extraInfos || {}));
|
|
105
110
|
this.code = code || 500;
|
|
@@ -144,10 +149,11 @@ class DescriptiveError extends Error {
|
|
|
144
149
|
this.code = code || 500;
|
|
145
150
|
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !(0, isset_1.isset)(this.options.code)))
|
|
146
151
|
delete this.code;
|
|
147
|
-
this.errorDescription = Object.assign({ msg: this.msg, code,
|
|
152
|
+
this.errorDescription = Object.assign({ msg: this.msg, message: this.msg, code,
|
|
148
153
|
ressource, originalError: err }, extraInfos);
|
|
154
|
+
(_a = (_b = this.errorDescription).originalError) !== null && _a !== void 0 ? _a : (_b.originalError = '');
|
|
149
155
|
if (err)
|
|
150
|
-
this.errorDescription.originalError
|
|
156
|
+
this.errorDescription.originalError += `${err.code ? err.code + ': ' : ''}${err.message || err.msg || err.toString()}`;
|
|
151
157
|
this.logs = errorLogs;
|
|
152
158
|
return errorLogs;
|
|
153
159
|
}
|
|
@@ -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;
|
|
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;AAElC,qFAA8E;AAE9E,SAAgB,WAAW,CAAC,uBAAuB,IAAI,OAAO,cAAc,CAAC,GAAG,EAAE,KAAK,EAAE,uBAAuB,CAAC,CAAA,CAAC,CAAC;AAAnH,kCAAmH;AAEnH,SAAgB,cAAc,CAAC,uBAAuB,IAAI,OAAO,cAAc,CAAC,GAAG,EAAE,KAAK,EAAE,uBAAuB,CAAC,CAAA,CAAC,CAAC;AAAtH,wCAAsH;AAEtH,SAAgB,kBAAkB,CAAC,uBAAuB,IAAI,OAAO,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,uBAAuB,CAAC,CAAA,CAAC,CAAC;AAAzH,gDAAyH;AAEzH,SAAgB,qBAAqB,CAAC,uBAAuB,IAAI,OAAO,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,uBAAuB,CAAC,CAAA,CAAC,CAAC;AAA5H,sDAA4H;AAE5H,SAA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,4CAqHC"}
|
package/package.json
CHANGED
package/src/error-utils.ts
CHANGED
|
@@ -57,10 +57,18 @@ function extraInfosRendererDefault(extraInfos) {
|
|
|
57
57
|
|
|
58
58
|
export class DescriptiveError extends Error {
|
|
59
59
|
/** Full error infos, extra infos + message and code...etc as object */
|
|
60
|
-
errorDescription: {
|
|
60
|
+
errorDescription: {
|
|
61
|
+
code: number
|
|
62
|
+
msg: string
|
|
63
|
+
message: string
|
|
64
|
+
originalError?: string
|
|
65
|
+
[k: string]: any
|
|
66
|
+
} = {} as any
|
|
61
67
|
/** Http code. Eg: 404, 403... */
|
|
62
68
|
code?: number
|
|
63
69
|
msg: string
|
|
70
|
+
/** Alias since .msg is not always obvious to find */
|
|
71
|
+
message: string
|
|
64
72
|
options: ErrorOptions
|
|
65
73
|
/** Logging of the error is async, unless disabled, so that it wait one frame to allow to log it manually */
|
|
66
74
|
hasBeenLogged = false
|
|
@@ -70,6 +78,7 @@ export class DescriptiveError extends Error {
|
|
|
70
78
|
super(msg)
|
|
71
79
|
delete options.errMsgId
|
|
72
80
|
this.msg = msg
|
|
81
|
+
this.message = msg
|
|
73
82
|
const { doNotWaitOneFrameForLog = false, ...optionsClean } = options
|
|
74
83
|
this.options = optionsClean
|
|
75
84
|
if (optionsClean.err) optionsClean.err.hasBeenLogged = true
|
|
@@ -142,12 +151,15 @@ export class DescriptiveError extends Error {
|
|
|
142
151
|
if (this.options.doNotDisplayCode || (this.options.hasOwnProperty('code') && !isset(this.options.code))) delete this.code
|
|
143
152
|
this.errorDescription = {
|
|
144
153
|
msg: this.msg,
|
|
154
|
+
message: this.msg,
|
|
145
155
|
code,
|
|
146
156
|
ressource,
|
|
147
157
|
originalError: err,
|
|
148
158
|
...extraInfos,
|
|
149
159
|
}
|
|
150
|
-
|
|
160
|
+
|
|
161
|
+
this.errorDescription.originalError ??= ''
|
|
162
|
+
if (err) this.errorDescription.originalError += `${err.code ? err.code + ': ' : ''}${err.message || err.msg || err.toString()}`
|
|
151
163
|
|
|
152
164
|
this.logs = errorLogs
|
|
153
165
|
|