@middy/http-json-body-parser 3.0.0-alpha.2 → 3.0.0-alpha.6

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/index.js +4 -2
  3. package/package.json +6 -5
package/README.md CHANGED
@@ -46,7 +46,7 @@ npm install --save @middy/http-json-body-parser
46
46
 
47
47
  ## Options
48
48
 
49
- - reviver (function) (optional): A [reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters) parameter may be passed which will be used `JSON.parse`ing the body.
49
+ - `reviver` function (optional): A [reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#Parameters) parameter may be passed which will be used `JSON.parse`ing the body.
50
50
 
51
51
 
52
52
  ## Sample usage
package/index.js CHANGED
@@ -21,8 +21,10 @@ const httpJsonBodyParserMiddleware = (opts = {}) => {
21
21
  const data = request.event.isBase64Encoded ? Buffer.from(body, 'base64').toString() : body;
22
22
  request.event.rawBody = body;
23
23
  request.event.body = JSON.parse(data, options.reviver);
24
- } catch (e) {
25
- throw createError(422, 'Content type defined as JSON but an invalid JSON was provided');
24
+ } catch (cause) {
25
+ const error = createError(422, 'Invalid or malformed JSON was provided');
26
+ error.cause = cause;
27
+ throw error;
26
28
  }
27
29
  }
28
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-json-body-parser",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.6",
4
4
  "description": "Http JSON body parser middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -18,7 +18,8 @@
18
18
  ],
19
19
  "scripts": {
20
20
  "test": "npm run test:unit",
21
- "test:unit": "ava"
21
+ "test:unit": "ava",
22
+ "test:benchmark": "node __benchmarks__/index.js"
22
23
  },
23
24
  "license": "MIT",
24
25
  "keywords": [
@@ -49,10 +50,10 @@
49
50
  },
50
51
  "homepage": "https://github.com/middyjs/middy#readme",
51
52
  "dependencies": {
52
- "@middy/util": "^3.0.0-alpha.2"
53
+ "@middy/util": "^3.0.0-alpha.6"
53
54
  },
54
55
  "devDependencies": {
55
- "@middy/core": "^3.0.0-alpha.2"
56
+ "@middy/core": "^3.0.0-alpha.6"
56
57
  },
57
- "gitHead": "de30419273ecbff08f367f47c7e320ec981cf145"
58
+ "gitHead": "176660ed3e0716d6bfb635c77251b301e0e24720"
58
59
  }