@basis-theory/basis-theory-reactor-formulas-sdk-js 1.5.1 → 1.5.2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basis-theory/basis-theory-reactor-formulas-sdk-js",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"description": "Javascript SDK for building Basis Theory reactor formulas",
|
|
5
5
|
"repository": "https://github.com/Basis-Theory/basistheory-reactor-formulas-sdk-js",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -1,41 +1,66 @@
|
|
|
1
|
+
// this method avoids a TypeError if the error contains a circular reference, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
|
|
2
|
+
const safeStringify = (obj) => {
|
|
3
|
+
const seen = new WeakSet();
|
|
4
|
+
|
|
5
|
+
return JSON.stringify(obj, (key, value) => {
|
|
6
|
+
if (typeof value === 'object' && value !== undefined) {
|
|
7
|
+
if (seen.has(value)) {
|
|
8
|
+
// circular reference found, return a placeholder or skip it
|
|
9
|
+
return '[Circular]';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
seen.add(value);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return value;
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
|
|
1
19
|
const sanitizeErrors = (errors) => {
|
|
2
20
|
const sanitizedErrors = {};
|
|
3
21
|
|
|
4
22
|
const fallbackErrorMessage =
|
|
5
23
|
'Something went wrong. Please try again. If the problem persists, please contact support@basistheory.com.';
|
|
6
24
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
sanitizedErrors['error'] =
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
? JSON.stringify(e)
|
|
24
|
-
: e?.toString() ?? fallbackErrorMessage
|
|
25
|
-
);
|
|
26
|
-
} else if (typeof errors[property] === 'object') {
|
|
27
|
-
sanitizedErrors[property] = [JSON.stringify(errors[property])];
|
|
28
|
-
} else if (errors[property]) {
|
|
29
|
-
sanitizedErrors[property] = [errors[property].toString()];
|
|
25
|
+
try {
|
|
26
|
+
const mapSanitizedError = (error) =>
|
|
27
|
+
error.map((e) =>
|
|
28
|
+
typeof e === 'object'
|
|
29
|
+
? safeStringify(e)
|
|
30
|
+
: e?.toString() ?? fallbackErrorMessage
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (Array.isArray(errors)) {
|
|
34
|
+
sanitizedErrors['error'] = mapSanitizedError(errors);
|
|
35
|
+
} else if (errors instanceof Error) {
|
|
36
|
+
if (errors.message) {
|
|
37
|
+
sanitizedErrors['error'] = [errors.message];
|
|
38
|
+
} else if (errors.name !== 'Error') {
|
|
39
|
+
// "Error" is not helpful as a message
|
|
40
|
+
sanitizedErrors['error'] = [errors.name];
|
|
30
41
|
} else {
|
|
31
|
-
sanitizedErrors[
|
|
42
|
+
sanitizedErrors['error'] = [fallbackErrorMessage];
|
|
32
43
|
}
|
|
44
|
+
} else if (typeof errors === 'object') {
|
|
45
|
+
for (const property in errors) {
|
|
46
|
+
if (Array.isArray(errors[property])) {
|
|
47
|
+
sanitizedErrors[property] = mapSanitizedError(errors[property]);
|
|
48
|
+
} else if (typeof errors[property] === 'object') {
|
|
49
|
+
sanitizedErrors[property] = [safeStringify(errors[property])];
|
|
50
|
+
} else if (errors[property]) {
|
|
51
|
+
sanitizedErrors[property] = [errors[property].toString()];
|
|
52
|
+
} else {
|
|
53
|
+
sanitizedErrors[property] = [fallbackErrorMessage];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
} else if (typeof errors === 'string') {
|
|
57
|
+
sanitizedErrors['error'] = [errors];
|
|
58
|
+
} else if (errors) {
|
|
59
|
+
sanitizedErrors['error'] = [errors.toString()];
|
|
60
|
+
} else {
|
|
61
|
+
sanitizedErrors['error'] = [fallbackErrorMessage];
|
|
33
62
|
}
|
|
34
|
-
}
|
|
35
|
-
sanitizedErrors['error'] = [errors];
|
|
36
|
-
} else if (errors) {
|
|
37
|
-
sanitizedErrors['error'] = [errors.toString()];
|
|
38
|
-
} else {
|
|
63
|
+
} catch {
|
|
39
64
|
sanitizedErrors['error'] = [fallbackErrorMessage];
|
|
40
65
|
}
|
|
41
66
|
|