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