bootpress 10.0.2 → 10.0.4

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 (2) hide show
  1. package/index.js +6 -3
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const { as, asStrict, log } = require("./helpers");
2
+ const { HttpError } = require("./types");
2
3
 
3
4
  const protectedProperties = [
4
5
  "toString",
@@ -7,11 +8,11 @@ const protectedProperties = [
7
8
  "toLocaleString"
8
9
  ]
9
10
 
10
- function reply(res, status, data) {
11
- if (typeof data == "object") {
11
+ function reply(/**@type {import("express").Response} */ res, status, data) {
12
+ if (typeof data === "object") {
12
13
  res.status(status).json(data);
13
14
  } else {
14
- res.status(status).send(data);
15
+ res.status(status).send(String(data));
15
16
  }
16
17
  }
17
18
 
@@ -247,6 +248,7 @@ function PassBodyAs(type, config = { messageTemplate: "Malformed Request Body\n{
247
248
  const req = args.at(-3);
248
249
  const res = args.at(-2);
249
250
  try {
251
+ if (req.body === null || req.body === undefined) throw new HttpError(400, "Request body is mandatory");
250
252
  return actualHandler(asStrict(req.body, type, config))(req, res);
251
253
  } catch (e) {
252
254
  const status = e.status ?? 500;
@@ -256,6 +258,7 @@ function PassBodyAs(type, config = { messageTemplate: "Malformed Request Body\n{
256
258
  } else {
257
259
  return (req, res) => {
258
260
  try {
261
+ if (req.body === null || req.body === undefined) throw new HttpError(400, "Request body is mandatory");
259
262
  return actualHandler(...args, asStrict(req.body, type, config))(req, res);
260
263
  } catch (e) {
261
264
  const status = e.status ?? 500;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bootpress",
3
- "version": "10.0.2",
3
+ "version": "10.0.4",
4
4
  "description": "REST service methods for express",
5
5
  "main": "index.js",
6
6
  "repository": {