@lightsparkdev/core 1.0.15 → 1.0.16

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.0.16
4
+
5
+ ### Patch Changes
6
+
7
+ - cb28f0e: - Serialize errors that have messages but not own properties
8
+
3
9
  ## 1.0.15
4
10
 
5
11
  ### Patch Changes
@@ -732,9 +732,13 @@ function errorToJSON(err) {
732
732
  if (!err) {
733
733
  return null;
734
734
  }
735
- if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
735
+ if (typeof err === "object" && "toJSON" in err && typeof err.toJSON === "function") {
736
736
  return err.toJSON();
737
737
  }
738
+ if (typeof err === "object" && /* This happens for certain errors like DOMException: */
739
+ Object.getOwnPropertyNames(err).length === 0 && "message" in err && typeof err.message === "string") {
740
+ return { message: err.message };
741
+ }
738
742
  return JSON.parse(
739
743
  JSON.stringify(err, Object.getOwnPropertyNames(err))
740
744
  );
package/dist/index.cjs CHANGED
@@ -1135,9 +1135,13 @@ function errorToJSON(err) {
1135
1135
  if (!err) {
1136
1136
  return null;
1137
1137
  }
1138
- if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
1138
+ if (typeof err === "object" && "toJSON" in err && typeof err.toJSON === "function") {
1139
1139
  return err.toJSON();
1140
1140
  }
1141
+ if (typeof err === "object" && /* This happens for certain errors like DOMException: */
1142
+ Object.getOwnPropertyNames(err).length === 0 && "message" in err && typeof err.message === "string") {
1143
+ return { message: err.message };
1144
+ }
1141
1145
  return JSON.parse(
1142
1146
  JSON.stringify(err, Object.getOwnPropertyNames(err))
1143
1147
  );
package/dist/index.js CHANGED
@@ -40,7 +40,7 @@ import {
40
40
  setLocalStorageBoolean,
41
41
  sleep,
42
42
  urlsafe_b64decode
43
- } from "./chunk-ZLX5HJ4C.js";
43
+ } from "./chunk-JTLRW26V.js";
44
44
 
45
45
  // src/Logger.ts
46
46
  var Logger = class {
@@ -807,9 +807,13 @@ function errorToJSON(err) {
807
807
  if (!err) {
808
808
  return null;
809
809
  }
810
- if (typeof err === "object" && err !== null && "toJSON" in err && typeof err.toJSON === "function") {
810
+ if (typeof err === "object" && "toJSON" in err && typeof err.toJSON === "function") {
811
811
  return err.toJSON();
812
812
  }
813
+ if (typeof err === "object" && /* This happens for certain errors like DOMException: */
814
+ Object.getOwnPropertyNames(err).length === 0 && "message" in err && typeof err.message === "string") {
815
+ return { message: err.message };
816
+ }
813
817
  return JSON.parse(
814
818
  JSON.stringify(err, Object.getOwnPropertyNames(err))
815
819
  );
@@ -39,7 +39,7 @@ import {
39
39
  setLocalStorageBoolean,
40
40
  sleep,
41
41
  urlsafe_b64decode
42
- } from "../chunk-ZLX5HJ4C.js";
42
+ } from "../chunk-JTLRW26V.js";
43
43
  export {
44
44
  CurrencyUnit,
45
45
  abbrCurrencyUnit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -43,12 +43,22 @@ export function errorToJSON(err: unknown) {
43
43
  }
44
44
  if (
45
45
  typeof err === "object" &&
46
- err !== null &&
47
46
  "toJSON" in err &&
48
47
  typeof err.toJSON === "function"
49
48
  ) {
50
49
  return err.toJSON() as JSONType;
51
50
  }
51
+
52
+ if (
53
+ typeof err === "object" &&
54
+ /* This happens for certain errors like DOMException: */
55
+ Object.getOwnPropertyNames(err).length === 0 &&
56
+ "message" in err &&
57
+ typeof err.message === "string"
58
+ ) {
59
+ return { message: err.message };
60
+ }
61
+
52
62
  return JSON.parse(
53
63
  JSON.stringify(err, Object.getOwnPropertyNames(err)),
54
64
  ) as JSONType;