@datapos/datapos-shared 0.3.569 → 0.3.572
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.
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
class c extends Error {
|
|
2
2
|
locator;
|
|
3
|
-
//
|
|
3
|
+
// Error locator 'package.module.method'
|
|
4
4
|
constructor(s, o, r) {
|
|
5
5
|
super(s, r), this.name = "DPUError", this.locator = o;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
class
|
|
8
|
+
class y extends c {
|
|
9
|
+
constructor(s, o, r) {
|
|
10
|
+
super(s, o, r), this.name = "AppError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
class E extends c {
|
|
9
14
|
body;
|
|
10
15
|
// Sanitized snapshot of the response body
|
|
11
16
|
constructor(s, o, r, t) {
|
|
12
|
-
super(s, o, t), this.name = "APIError", this.body =
|
|
17
|
+
super(s, o, t), this.name = "APIError", this.body = l(r ?? void 0);
|
|
13
18
|
}
|
|
14
19
|
}
|
|
15
|
-
class
|
|
20
|
+
class d extends c {
|
|
16
21
|
constructor(s, o, r) {
|
|
17
22
|
super(s, o, r), this.name = "EngineError";
|
|
18
23
|
}
|
|
@@ -22,14 +27,14 @@ class m extends c {
|
|
|
22
27
|
super(s, o, r), this.name = "ConnectorError";
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
|
-
class
|
|
30
|
+
class i extends c {
|
|
26
31
|
body;
|
|
27
|
-
// Sanitized
|
|
32
|
+
// Sanitized portion of the response body
|
|
28
33
|
constructor(s, o, r, t) {
|
|
29
|
-
super(s, o, t), this.name = "FetchError", this.body =
|
|
34
|
+
super(s, o, t), this.name = "FetchError", this.body = l(r ?? void 0);
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
|
-
async function
|
|
37
|
+
async function b(e, s, o) {
|
|
33
38
|
const r = ` - ${e.statusText}`, t = `${s} Response status '${e.status}${e.statusText ? r : ""}' received.`;
|
|
34
39
|
let n;
|
|
35
40
|
try {
|
|
@@ -37,12 +42,12 @@ async function y(e, s, o) {
|
|
|
37
42
|
} catch (u) {
|
|
38
43
|
n = `<body unavailable: ${a(u).message}>`;
|
|
39
44
|
}
|
|
40
|
-
return new
|
|
45
|
+
return new i(t, o, n);
|
|
41
46
|
}
|
|
42
|
-
function
|
|
47
|
+
function k(e) {
|
|
43
48
|
return e.map((s) => s.message).join(" ");
|
|
44
49
|
}
|
|
45
|
-
function
|
|
50
|
+
function p(e) {
|
|
46
51
|
try {
|
|
47
52
|
e();
|
|
48
53
|
} catch {
|
|
@@ -86,50 +91,49 @@ function h(e) {
|
|
|
86
91
|
t = { body: n.body, locator: n.locator, message: r.message, name: "FetchError", stack: r.stack }, r = r.cause == null ? null : a(r.cause);
|
|
87
92
|
break;
|
|
88
93
|
}
|
|
89
|
-
case
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
break;
|
|
94
|
+
// case 'DPUError': {
|
|
95
|
+
// const typedCause = cause as DPUError;
|
|
96
|
+
// serialisedError = { body: undefined, locator: typedCause.locator, message: cause.message, name: 'DPUError', stack: cause.stack };
|
|
97
|
+
// cause = cause.cause == null ? null : normalizeToError(cause.cause);
|
|
98
|
+
// break;
|
|
99
|
+
// }
|
|
96
100
|
default:
|
|
97
|
-
|
|
101
|
+
r.name ? (t = { body: void 0, locator: "", message: r.message, name: r.name, stack: r.stack }, r = r.cause == null ? null : a(r.cause)) : (t = { body: void 0, locator: "", message: f(r), name: "Error", stack: void 0 }, r = null);
|
|
98
102
|
}
|
|
99
103
|
/(?:\.{3}|[.!?])$/.test(t.message) || (t.message += "."), o.push(t);
|
|
100
104
|
}
|
|
101
|
-
return
|
|
105
|
+
return o;
|
|
102
106
|
}
|
|
103
|
-
function
|
|
107
|
+
function w(e) {
|
|
104
108
|
if (e.length === 0) return;
|
|
105
109
|
let s;
|
|
106
110
|
for (const o of e.toReversed()) {
|
|
107
111
|
let r;
|
|
108
112
|
switch (o.name) {
|
|
109
113
|
case "APIError":
|
|
110
|
-
r = new
|
|
114
|
+
r = new E(o.message, o.locator, o.body, { cause: s });
|
|
111
115
|
break;
|
|
112
116
|
case "ConnectorError":
|
|
113
117
|
r = new m(o.message, o.locator, { cause: s });
|
|
114
118
|
break;
|
|
115
119
|
case "EngineError":
|
|
116
|
-
r = new
|
|
120
|
+
r = new d(o.message, o.locator, { cause: s });
|
|
117
121
|
break;
|
|
118
122
|
case "FetchError":
|
|
119
|
-
r = new
|
|
120
|
-
break;
|
|
121
|
-
case "DPUError":
|
|
122
|
-
r = new c(o.message, o.locator, { cause: s });
|
|
123
|
+
r = new i(o.message, o.locator, o.body, { cause: s });
|
|
123
124
|
break;
|
|
125
|
+
// case 'DPUError':
|
|
126
|
+
// error = new DPUError(serialised.message, serialised.locator, { cause: rebuiltError });
|
|
127
|
+
// break;
|
|
124
128
|
default:
|
|
125
|
-
|
|
129
|
+
r = new Error(o.message, { cause: s }), r.name = o.name;
|
|
126
130
|
break;
|
|
127
131
|
}
|
|
128
132
|
o.stack !== void 0 && (r.stack = o.stack), s = r;
|
|
129
133
|
}
|
|
130
134
|
return s;
|
|
131
135
|
}
|
|
132
|
-
function
|
|
136
|
+
function f(e) {
|
|
133
137
|
let s;
|
|
134
138
|
try {
|
|
135
139
|
s = JSON.stringify(e);
|
|
@@ -138,20 +142,21 @@ function g(e) {
|
|
|
138
142
|
}
|
|
139
143
|
return s === "" && (s = "Unknown error"), s;
|
|
140
144
|
}
|
|
141
|
-
function
|
|
145
|
+
function l(e) {
|
|
142
146
|
if (!(e == null || e === ""))
|
|
143
147
|
return e.length > 2048 ? `${e.slice(0, 2048)}... [truncated]` : e;
|
|
144
148
|
}
|
|
145
149
|
export {
|
|
146
|
-
|
|
150
|
+
E as APIError,
|
|
151
|
+
y as AppError,
|
|
147
152
|
m as ConnectorError,
|
|
148
153
|
c as DPUError,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
+
d as EngineError,
|
|
155
|
+
i as FetchError,
|
|
156
|
+
b as buildFetchError,
|
|
157
|
+
k as concatenateSerialisedErrorMessages,
|
|
158
|
+
p as ignoreErrors,
|
|
154
159
|
a as normalizeToError,
|
|
155
160
|
h as serialiseError,
|
|
156
|
-
|
|
161
|
+
w as unserialiseError
|
|
157
162
|
};
|
|
@@ -9,6 +9,9 @@ export declare class DPUError extends Error {
|
|
|
9
9
|
readonly locator: string;
|
|
10
10
|
constructor(message: string, locator: string, options?: ErrorOptions);
|
|
11
11
|
}
|
|
12
|
+
export declare class AppError extends DPUError {
|
|
13
|
+
constructor(message: string, locator: string, options?: ErrorOptions);
|
|
14
|
+
}
|
|
12
15
|
export declare class APIError extends DPUError {
|
|
13
16
|
readonly body: string | undefined;
|
|
14
17
|
constructor(message: string, locator: string, body: string | undefined, options?: ErrorOptions);
|
|
@@ -23,31 +26,13 @@ export declare class FetchError extends DPUError {
|
|
|
23
26
|
readonly body: string | undefined;
|
|
24
27
|
constructor(message: string, locator: string, body: string | undefined, options?: ErrorOptions);
|
|
25
28
|
}
|
|
26
|
-
/** Builds a {@link FetchError} from an HTTP response.
|
|
27
|
-
* The response body is eagerly read so it can be included in error logs even after the response stream is closed.
|
|
28
|
-
*/
|
|
29
29
|
export declare function buildFetchError(response: {
|
|
30
30
|
status: number;
|
|
31
31
|
statusText: string;
|
|
32
32
|
text: () => Promise<string>;
|
|
33
33
|
}, message: string, locator: string): Promise<FetchError>;
|
|
34
|
-
/** Concatenates serialized error messages into a single string. */
|
|
35
34
|
export declare function concatenateSerialisedErrorMessages(serialisedErrors: SerialisedError[]): string;
|
|
36
|
-
/** Ignore best-effort cleanup errors to keep teardown noise-free. */
|
|
37
35
|
export declare function ignoreErrors(action: () => void): void;
|
|
38
|
-
/** Normalizes an unknown thrown value into an {@link Error}.
|
|
39
|
-
* This function should be used at error boundaries to guarantee consistent error handling.
|
|
40
|
-
*/
|
|
41
36
|
export declare function normalizeToError(value: unknown): Error;
|
|
42
|
-
/** Serializes an error and its cause chain into a flat structure.
|
|
43
|
-
* - Errors are ordered from outermost to root cause.
|
|
44
|
-
* - Cycles in the cause chain are safely ignored.
|
|
45
|
-
* - Messages are normalized to end with punctuation.
|
|
46
|
-
*/
|
|
47
37
|
export declare function serialiseError(error?: unknown): SerialisedError[];
|
|
48
|
-
/** Unserialises an array of {@link SerialisedError} objects back into an error with a cause chain.
|
|
49
|
-
* - Reconstructs the appropriate error class based on serialized properties.
|
|
50
|
-
* - Chains errors from outermost to root cause using the `cause` option.
|
|
51
|
-
* - Returns `undefined` if the input array is empty.
|
|
52
|
-
*/
|
|
53
38
|
export declare function unserialiseError(serialisedErrors: SerialisedError[]): Error | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datapos/datapos-shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.572",
|
|
4
4
|
"description": "A library containing common constants, types and utilities used across all Data Positioning projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Jonathan Terrell <terrell.jm@gmail.com>",
|