@steve31415/baselib 3.40.0 → 3.40.1
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.
- package/dist/log-core.js +18 -1
- package/package.json +1 -1
package/dist/log-core.js
CHANGED
|
@@ -22,6 +22,23 @@ function errorCode(err) {
|
|
|
22
22
|
return code;
|
|
23
23
|
return undefined;
|
|
24
24
|
}
|
|
25
|
+
/** A non-Error cause as text. A plain object (gaxios 7 sets a Google API
|
|
26
|
+
* error's cause to the AIP-193 body { code, message, status }) is rendered
|
|
27
|
+
* as JSON, which String() would flatten to "[object Object]" (watchdog task
|
|
28
|
+
* 4454314a, 2026-10-28); an object JSON cannot render falls back to String(). */
|
|
29
|
+
function causeText(cause) {
|
|
30
|
+
if (typeof cause === 'object' && cause !== null) {
|
|
31
|
+
try {
|
|
32
|
+
const json = JSON.stringify(cause);
|
|
33
|
+
if (typeof json === 'string')
|
|
34
|
+
return json;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
// circular or a throwing toJSON: fall through
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return String(cause);
|
|
41
|
+
}
|
|
25
42
|
export function serializeError(err) {
|
|
26
43
|
if (err instanceof Error) {
|
|
27
44
|
const out = { name: err.name, message: err.message };
|
|
@@ -36,7 +53,7 @@ export function serializeError(err) {
|
|
|
36
53
|
out.cause.code = causeCode;
|
|
37
54
|
}
|
|
38
55
|
else if (err.cause !== undefined) {
|
|
39
|
-
out.cause = { name: 'cause', message: truncate(
|
|
56
|
+
out.cause = { name: 'cause', message: truncate(causeText(err.cause), 500) };
|
|
40
57
|
}
|
|
41
58
|
return out;
|
|
42
59
|
}
|
package/package.json
CHANGED