@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.
- package/README.md +1 -1
- package/index.js +4 -2
- 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
|
|
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 (
|
|
25
|
-
|
|
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.
|
|
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.
|
|
53
|
+
"@middy/util": "^3.0.0-alpha.6"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
|
-
"@middy/core": "^3.0.0-alpha.
|
|
56
|
+
"@middy/core": "^3.0.0-alpha.6"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "176660ed3e0716d6bfb635c77251b301e0e24720"
|
|
58
59
|
}
|