@plusscommunities/pluss-core-aws 1.5.2-beta.0 → 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.
@@ -1,22 +1,29 @@
1
- const replaceErrors = (key, value) => {
2
- if (value instanceof Error) {
3
- var error = {};
4
- Object.getOwnPropertyNames(value).forEach(function (key) {
5
- error[key] = value[key];
6
- });
7
- return error;
8
- }
9
- return value;
1
+ const getCircularReplacer = () => {
2
+ const seen = new WeakSet();
3
+ return (key, value) => {
4
+ if (value instanceof Error) {
5
+ var error = {};
6
+ Object.getOwnPropertyNames(value).forEach((key) => {
7
+ error[key] = value[key];
8
+ });
9
+ return error;
10
+ } else if (typeof value === "object" && value !== null) {
11
+ if (seen.has(value)) return;
12
+ seen.add(value);
13
+ }
14
+ return value;
15
+ };
10
16
  };
11
17
 
12
18
  module.exports = (statusCode, body) => {
13
19
  if ([400, 402, 422].includes(statusCode)) console.error(body);
20
+ const jsonBody = JSON.stringify(body.error || body, getCircularReplacer());
14
21
  return {
15
22
  statusCode,
16
23
  headers: {
17
24
  "Content-Type": "application/json",
18
25
  "Access-Control-Allow-Origin": "*",
19
26
  },
20
- body: JSON.stringify(body, replaceErrors),
27
+ body: jsonBody,
21
28
  };
22
29
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plusscommunities/pluss-core-aws",
3
- "version": "1.5.2-beta.0",
3
+ "version": "1.5.2",
4
4
  "description": "Core extension package for Pluss Communities platform",
5
5
  "scripts": {
6
6
  "betapatch": "npm version prepatch --preid=beta",