@datapos/datapos-shared 0.3.557 → 0.3.559
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,126 +1,129 @@
|
|
|
1
|
-
class
|
|
1
|
+
class a extends Error {
|
|
2
2
|
locator;
|
|
3
|
-
|
|
4
|
-
constructor(
|
|
5
|
-
super(
|
|
3
|
+
// Logical source of the error
|
|
4
|
+
constructor(o, s, r) {
|
|
5
|
+
super(o, r), this.name = "DPUError", this.locator = s;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
class
|
|
8
|
+
class l extends a {
|
|
9
|
+
body;
|
|
10
|
+
// Sanitized snapshot of the response body
|
|
11
|
+
constructor(o, s, r, n) {
|
|
12
|
+
super(o, s, n), this.name = "APIError", this.body = m(r ?? void 0);
|
|
13
|
+
}
|
|
9
14
|
}
|
|
10
|
-
class
|
|
15
|
+
class u extends a {
|
|
16
|
+
constructor(o, s, r) {
|
|
17
|
+
super(o, s, r), this.name = "EngineError";
|
|
18
|
+
}
|
|
11
19
|
}
|
|
12
|
-
class
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
class d extends a {
|
|
21
|
+
id;
|
|
22
|
+
// Connector identifier
|
|
23
|
+
constructor(o, s, r, n) {
|
|
24
|
+
super(o, s, n), this.name = "ConnectorError", this.id = r;
|
|
15
25
|
}
|
|
16
26
|
}
|
|
17
|
-
class
|
|
27
|
+
class i extends a {
|
|
18
28
|
body;
|
|
19
|
-
|
|
20
|
-
constructor(
|
|
21
|
-
super(
|
|
29
|
+
// Sanitized snapshot of the response body
|
|
30
|
+
constructor(o, s, r, n) {
|
|
31
|
+
super(o, s, n), this.name = "FetchError", this.body = m(r ?? void 0);
|
|
22
32
|
}
|
|
23
33
|
}
|
|
24
|
-
async function
|
|
25
|
-
const
|
|
26
|
-
let
|
|
34
|
+
async function b(e, o, s) {
|
|
35
|
+
const r = ` - ${e.statusText}`, n = `${o} Response status '${e.status}${e.statusText ? r : ""}' received.`;
|
|
36
|
+
let c;
|
|
27
37
|
try {
|
|
28
|
-
|
|
38
|
+
c = await e.text();
|
|
29
39
|
} catch (f) {
|
|
30
|
-
|
|
40
|
+
c = `<body unavailable: ${t(f).message}>`;
|
|
31
41
|
}
|
|
32
|
-
return new
|
|
42
|
+
return new i(n, s, c);
|
|
33
43
|
}
|
|
34
|
-
function y(
|
|
35
|
-
return
|
|
44
|
+
function y(e) {
|
|
45
|
+
return e.map((o) => o.message).join(" ");
|
|
36
46
|
}
|
|
37
|
-
function
|
|
47
|
+
function k(e) {
|
|
38
48
|
try {
|
|
39
|
-
|
|
49
|
+
e();
|
|
40
50
|
} catch {
|
|
41
51
|
}
|
|
42
52
|
}
|
|
43
|
-
function
|
|
44
|
-
if (
|
|
45
|
-
if (typeof
|
|
46
|
-
if (typeof
|
|
47
|
-
if (typeof
|
|
48
|
-
if (typeof
|
|
53
|
+
function t(e) {
|
|
54
|
+
if (e instanceof Error) return e;
|
|
55
|
+
if (typeof e == "string") return new Error(e);
|
|
56
|
+
if (typeof e == "number" || typeof e == "boolean" || typeof e == "bigint") return new Error(String(e));
|
|
57
|
+
if (typeof e == "symbol") return new Error(e.description ?? "Unknown error");
|
|
58
|
+
if (typeof e == "object")
|
|
49
59
|
try {
|
|
50
|
-
return new Error(JSON.stringify(
|
|
60
|
+
return new Error(JSON.stringify(e));
|
|
51
61
|
} catch {
|
|
52
62
|
return new Error("Unknown error");
|
|
53
63
|
}
|
|
54
64
|
return new Error("Unknown error");
|
|
55
65
|
}
|
|
56
|
-
function
|
|
57
|
-
const
|
|
58
|
-
let
|
|
59
|
-
for (;
|
|
60
|
-
|
|
61
|
-
let
|
|
62
|
-
|
|
66
|
+
function h(e) {
|
|
67
|
+
const o = /* @__PURE__ */ new Set(), s = [];
|
|
68
|
+
let r = t(e);
|
|
69
|
+
for (; r != null && !o.has(r); ) {
|
|
70
|
+
o.add(r);
|
|
71
|
+
let n;
|
|
72
|
+
r instanceof l ? (n = { body: r.body, componentId: void 0, locator: r.locator, message: r.message, name: "APIError", stack: r.stack }, r = r.cause == null ? null : t(r.cause)) : r instanceof d ? (n = { body: void 0, componentId: r.id, locator: r.locator, message: r.message, name: "ConnectorError", stack: r.stack }, r = r.cause == null ? null : t(r.cause)) : r instanceof u ? (n = { body: void 0, componentId: void 0, locator: r.locator, message: r.message, name: "EngineError", stack: r.stack }, r = r.cause == null ? null : t(r.cause)) : r instanceof i ? (n = { body: r.body, componentId: void 0, locator: r.locator, message: r.message, name: "FetchError", stack: r.stack }, r = r.cause == null ? null : t(r.cause)) : r instanceof a ? (n = { body: void 0, componentId: void 0, locator: r.locator, message: r.message, name: "DPUError", stack: r.stack }, r = r.cause == null ? null : t(r.cause)) : r instanceof Error ? (n = { body: void 0, componentId: void 0, locator: "", message: r.message, name: r.name, stack: r.stack }, r = r.cause == null ? null : t(r.cause)) : (n = { body: void 0, componentId: void 0, locator: "", message: E(r), name: "Error", stack: void 0 }, r = null), /(?:\.{3}|[.!?])$/.test(n.message) || (n.message += "."), s.push(n);
|
|
63
73
|
}
|
|
64
|
-
return
|
|
74
|
+
return s;
|
|
65
75
|
}
|
|
66
|
-
function
|
|
67
|
-
if (
|
|
68
|
-
let
|
|
69
|
-
for (const
|
|
70
|
-
let
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// case 'WindowHandledPromiseRejectionError':
|
|
93
|
-
// error = new WindowHandledPromiseRejectionError(serialised.message, serialised.locator, { rebuiltError });
|
|
94
|
-
// break;
|
|
95
|
-
default:
|
|
96
|
-
console.log("Fallback"), e = new c(o.message, o.locator, { cause: s });
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
console.log(1111, e.stack, o.stack), o.stack !== void 0 && (e.stack = o.stack), console.log(2222, e.stack, o.stack), s = e;
|
|
76
|
+
function p(e) {
|
|
77
|
+
if (e.length === 0) return;
|
|
78
|
+
let o;
|
|
79
|
+
for (const s of e.toReversed()) {
|
|
80
|
+
let r;
|
|
81
|
+
switch (s.name) {
|
|
82
|
+
case "APIError":
|
|
83
|
+
r = new l(s.message, s.locator, s.body, { cause: o });
|
|
84
|
+
break;
|
|
85
|
+
case "ConnectorError":
|
|
86
|
+
r = new d(s.message, s.locator, s.componentId, { cause: o });
|
|
87
|
+
break;
|
|
88
|
+
case "EngineError":
|
|
89
|
+
r = new u(s.message, s.locator, { cause: o });
|
|
90
|
+
break;
|
|
91
|
+
case "FetchError":
|
|
92
|
+
r = new i(s.message, s.locator, s.body, { cause: o });
|
|
93
|
+
break;
|
|
94
|
+
case "DPUError":
|
|
95
|
+
r = new a(s.message, s.locator, { cause: o });
|
|
96
|
+
break;
|
|
97
|
+
default:
|
|
98
|
+
r = new Error(s.message, { cause: o }), r.name = s.name;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
s.stack !== void 0 && (r.stack = s.stack), o = r;
|
|
100
102
|
}
|
|
101
|
-
return
|
|
103
|
+
return o;
|
|
102
104
|
}
|
|
103
|
-
function E(
|
|
104
|
-
let
|
|
105
|
+
function E(e) {
|
|
106
|
+
let o;
|
|
105
107
|
try {
|
|
106
|
-
|
|
108
|
+
o = JSON.stringify(e);
|
|
107
109
|
} catch {
|
|
108
|
-
typeof
|
|
110
|
+
typeof e == "symbol" ? o = e.description ?? "Unknown error" : typeof e == "bigint" ? o = e.toString() : o = "Unknown error";
|
|
109
111
|
}
|
|
110
|
-
return
|
|
112
|
+
return o === "" && (o = "Unknown error"), o;
|
|
111
113
|
}
|
|
112
|
-
function
|
|
113
|
-
if (!(
|
|
114
|
-
return
|
|
114
|
+
function m(e) {
|
|
115
|
+
if (!(e == null || e === ""))
|
|
116
|
+
return e.length > 2048 ? `${e.slice(0, 2048)}... [truncated]` : e;
|
|
115
117
|
}
|
|
116
118
|
export {
|
|
117
|
-
|
|
119
|
+
l as APIError,
|
|
120
|
+
d as ConnectorError,
|
|
118
121
|
u as EngineError,
|
|
119
|
-
|
|
120
|
-
|
|
122
|
+
i as FetchError,
|
|
123
|
+
b as buildFetchError,
|
|
121
124
|
y as concatenateSerialisedErrorMessages,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
125
|
+
k as ignoreErrors,
|
|
126
|
+
t as normalizeToError,
|
|
127
|
+
h as serialiseError,
|
|
128
|
+
p as unserialiseError
|
|
126
129
|
};
|
|
@@ -1,72 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** HTTP response body (Fetch errors only). */ body: string | undefined;
|
|
9
|
-
/** Logical source of the error. */ locator: string;
|
|
10
|
-
/** Human-readable error message. */ message: string;
|
|
11
|
-
/** Error class or type name. */ name: string;
|
|
12
|
-
/** Stack trace, if available. */ stack: string | undefined;
|
|
1
|
+
export interface SerialisedError {
|
|
2
|
+
body: string | undefined;
|
|
3
|
+
componentId: string | undefined;
|
|
4
|
+
locator: string;
|
|
5
|
+
message: string;
|
|
6
|
+
name: string;
|
|
7
|
+
stack: string | undefined;
|
|
13
8
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
declare class DataPosError extends Error {
|
|
18
|
-
readonly locator: string; /** Logical source of the error. */
|
|
9
|
+
declare class DPUError extends Error {
|
|
10
|
+
readonly locator: string;
|
|
19
11
|
constructor(message: string, locator: string, options?: ErrorOptions);
|
|
20
12
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
declare class ApplicationError extends DataPosError {
|
|
25
|
-
}
|
|
26
|
-
/** Represents API-related failures.
|
|
27
|
-
* Typically thrown when backend requests fail or return invalid responses.
|
|
28
|
-
*/
|
|
29
|
-
declare class APIError extends ApplicationError {
|
|
13
|
+
export declare class APIError extends DPUError {
|
|
14
|
+
readonly body: string | undefined;
|
|
15
|
+
constructor(message: string, locator: string, body: string | undefined, options?: ErrorOptions);
|
|
30
16
|
}
|
|
31
|
-
|
|
32
|
-
declare class EngineError extends ApplicationError {
|
|
17
|
+
export declare class EngineError extends DPUError {
|
|
33
18
|
constructor(message: string, locator: string, options?: ErrorOptions);
|
|
34
19
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
20
|
+
export declare class ConnectorError extends DPUError {
|
|
21
|
+
readonly id: string | undefined;
|
|
22
|
+
constructor(message: string, locator: string, id: string | undefined, options?: ErrorOptions);
|
|
23
|
+
}
|
|
24
|
+
export declare class FetchError extends DPUError {
|
|
25
|
+
readonly body: string | undefined;
|
|
26
|
+
constructor(message: string, locator: string, body: string | undefined, options?: ErrorOptions);
|
|
41
27
|
}
|
|
42
28
|
/** Builds a {@link FetchError} from an HTTP response.
|
|
43
29
|
* The response body is eagerly read so it can be included in error logs even after the response stream is closed.
|
|
44
30
|
*/
|
|
45
|
-
declare function buildFetchError(response: {
|
|
31
|
+
export declare function buildFetchError(response: {
|
|
46
32
|
status: number;
|
|
47
33
|
statusText: string;
|
|
48
34
|
text: () => Promise<string>;
|
|
49
35
|
}, message: string, locator: string): Promise<FetchError>;
|
|
50
36
|
/** Concatenates serialized error messages into a single string. */
|
|
51
|
-
declare function concatenateSerialisedErrorMessages(serialisedErrors: SerialisedError[]): string;
|
|
37
|
+
export declare function concatenateSerialisedErrorMessages(serialisedErrors: SerialisedError[]): string;
|
|
52
38
|
/** Ignore best-effort cleanup errors to keep teardown noise-free. */
|
|
53
|
-
declare function ignoreErrors(action: () => void): void;
|
|
39
|
+
export declare function ignoreErrors(action: () => void): void;
|
|
54
40
|
/** Normalizes an unknown thrown value into an {@link Error}.
|
|
55
41
|
* This function should be used at error boundaries to guarantee consistent error handling.
|
|
56
42
|
*/
|
|
57
|
-
declare function normalizeToError(value: unknown): Error;
|
|
43
|
+
export declare function normalizeToError(value: unknown): Error;
|
|
58
44
|
/** Serializes an error and its cause chain into a flat structure.
|
|
59
45
|
* - Errors are ordered from outermost to root cause.
|
|
60
46
|
* - Cycles in the cause chain are safely ignored.
|
|
61
47
|
* - Messages are normalized to end with punctuation.
|
|
62
48
|
*/
|
|
63
|
-
declare function serialiseError(error?: unknown): SerialisedError[];
|
|
49
|
+
export declare function serialiseError(error?: unknown): SerialisedError[];
|
|
64
50
|
/** Unserialises an array of {@link SerialisedError} objects back into an error with a cause chain.
|
|
65
51
|
* - Reconstructs the appropriate error class based on serialized properties.
|
|
66
52
|
* - Chains errors from outermost to root cause using the `cause` option.
|
|
67
53
|
* - Returns `undefined` if the input array is empty.
|
|
68
54
|
*/
|
|
69
|
-
declare function unserialiseError(serialisedErrors: SerialisedError[]): Error | undefined;
|
|
70
|
-
export
|
|
71
|
-
export { APIError, EngineError, FetchError };
|
|
72
|
-
export { buildFetchError, concatenateSerialisedErrorMessages, ignoreErrors, normalizeToError, serialiseError, unserialiseError };
|
|
55
|
+
export declare function unserialiseError(serialisedErrors: SerialisedError[]): Error | undefined;
|
|
56
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datapos/datapos-shared",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.559",
|
|
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>",
|