@datapos/datapos-shared 0.3.570 → 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
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
|
}
|
|
@@ -24,12 +29,12 @@ class m extends c {
|
|
|
24
29
|
}
|
|
25
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
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 {
|
|
@@ -39,10 +44,10 @@ async function y(e, s, o) {
|
|
|
39
44
|
}
|
|
40
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,38 +91,40 @@ 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
|
-
|
|
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
|
+
// }
|
|
93
100
|
default:
|
|
94
|
-
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:
|
|
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);
|
|
95
102
|
}
|
|
96
103
|
/(?:\.{3}|[.!?])$/.test(t.message) || (t.message += "."), o.push(t);
|
|
97
104
|
}
|
|
98
105
|
return o;
|
|
99
106
|
}
|
|
100
|
-
function
|
|
107
|
+
function w(e) {
|
|
101
108
|
if (e.length === 0) return;
|
|
102
109
|
let s;
|
|
103
110
|
for (const o of e.toReversed()) {
|
|
104
111
|
let r;
|
|
105
112
|
switch (o.name) {
|
|
106
113
|
case "APIError":
|
|
107
|
-
r = new
|
|
114
|
+
r = new E(o.message, o.locator, o.body, { cause: s });
|
|
108
115
|
break;
|
|
109
116
|
case "ConnectorError":
|
|
110
117
|
r = new m(o.message, o.locator, { cause: s });
|
|
111
118
|
break;
|
|
112
119
|
case "EngineError":
|
|
113
|
-
r = new
|
|
120
|
+
r = new d(o.message, o.locator, { cause: s });
|
|
114
121
|
break;
|
|
115
122
|
case "FetchError":
|
|
116
123
|
r = new i(o.message, o.locator, o.body, { cause: s });
|
|
117
124
|
break;
|
|
118
|
-
case
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
// case 'DPUError':
|
|
126
|
+
// error = new DPUError(serialised.message, serialised.locator, { cause: rebuiltError });
|
|
127
|
+
// break;
|
|
121
128
|
default:
|
|
122
129
|
r = new Error(o.message, { cause: s }), r.name = o.name;
|
|
123
130
|
break;
|
|
@@ -126,7 +133,7 @@ function p(e) {
|
|
|
126
133
|
}
|
|
127
134
|
return s;
|
|
128
135
|
}
|
|
129
|
-
function
|
|
136
|
+
function f(e) {
|
|
130
137
|
let s;
|
|
131
138
|
try {
|
|
132
139
|
s = JSON.stringify(e);
|
|
@@ -140,15 +147,16 @@ function l(e) {
|
|
|
140
147
|
return e.length > 2048 ? `${e.slice(0, 2048)}... [truncated]` : e;
|
|
141
148
|
}
|
|
142
149
|
export {
|
|
143
|
-
|
|
150
|
+
E as APIError,
|
|
151
|
+
y as AppError,
|
|
144
152
|
m as ConnectorError,
|
|
145
153
|
c as DPUError,
|
|
146
|
-
|
|
154
|
+
d as EngineError,
|
|
147
155
|
i as FetchError,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
b as buildFetchError,
|
|
157
|
+
k as concatenateSerialisedErrorMessages,
|
|
158
|
+
p as ignoreErrors,
|
|
151
159
|
a as normalizeToError,
|
|
152
160
|
h as serialiseError,
|
|
153
|
-
|
|
161
|
+
w as unserialiseError
|
|
154
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>",
|