express-toolkit-pro 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +114 -2
- package/package.json +34 -4
- package/src/errors/ApiError.js +28 -0
- package/src/index.js +21 -0
- package/src/middleware/asyncHandler.js +8 -0
- package/src/middleware/errorHandler.js +32 -0
- package/src/middleware/notFound.js +12 -0
- package/src/middleware/rateLimiter.js +92 -0
- package/src/middleware/requestLogger.js +27 -0
- package/src/utils/ApiResponse.js +14 -0
- package/src/utils/pagination.js +37 -0
- package/src/validators/validateRequest.js +105 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 charan_456
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,115 @@
|
|
|
1
|
-
#
|
|
1
|
+
# express-toolkit-pro
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A reusable toolkit for building robust Express.js APIs.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ApiError: Structured HTTP API errors.
|
|
8
|
+
- asyncHandler: Handles rejected asynchronous Express routes.
|
|
9
|
+
- errorHandler: Centralized JSON error handling.
|
|
10
|
+
- notFound: Handles unknown routes.
|
|
11
|
+
- requestLogger: Logs completed HTTP requests and response times.
|
|
12
|
+
- rateLimiter: Limits requests per client.
|
|
13
|
+
- ApiResponse: Standardized API success responses.
|
|
14
|
+
- paginate: Calculates pagination metadata.
|
|
15
|
+
- validateRequest: Validates body, query, and route parameters.
|
|
16
|
+
|
|
17
|
+
## Requirements
|
|
18
|
+
|
|
19
|
+
- Node.js 18 or later.
|
|
20
|
+
- Express 4.18 or later.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
npm install express-toolkit-pro express
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
const express = require("express");
|
|
29
|
+
const {
|
|
30
|
+
asyncHandler,
|
|
31
|
+
errorHandler,
|
|
32
|
+
notFound,
|
|
33
|
+
requestLogger,
|
|
34
|
+
rateLimiter,
|
|
35
|
+
ApiResponse
|
|
36
|
+
} = require("express-toolkit-pro");
|
|
37
|
+
|
|
38
|
+
const app = express();
|
|
39
|
+
|
|
40
|
+
app.use(express.json());
|
|
41
|
+
app.use(requestLogger());
|
|
42
|
+
app.use(rateLimiter());
|
|
43
|
+
|
|
44
|
+
app.get("/users", asyncHandler(async (req, res) => {
|
|
45
|
+
const users = [{ id: 1, name: "Alex" }];
|
|
46
|
+
|
|
47
|
+
res.status(200).json(
|
|
48
|
+
new ApiResponse(200, users, "Users fetched successfully")
|
|
49
|
+
);
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
app.use(notFound);
|
|
53
|
+
app.use(errorHandler);
|
|
54
|
+
|
|
55
|
+
app.listen(3000);
|
|
56
|
+
|
|
57
|
+
## API Reference
|
|
58
|
+
|
|
59
|
+
### ApiError
|
|
60
|
+
|
|
61
|
+
new ApiError(statusCode, message, errors, stack);
|
|
62
|
+
|
|
63
|
+
Creates a structured HTTP error.
|
|
64
|
+
|
|
65
|
+
### asyncHandler
|
|
66
|
+
|
|
67
|
+
Wraps asynchronous route handlers and forwards rejected promises to Express error handling.
|
|
68
|
+
|
|
69
|
+
### errorHandler
|
|
70
|
+
|
|
71
|
+
Centralized error-handling middleware. Register after routes.
|
|
72
|
+
|
|
73
|
+
### notFound
|
|
74
|
+
|
|
75
|
+
Handles unknown routes. Register after application routes.
|
|
76
|
+
|
|
77
|
+
### requestLogger
|
|
78
|
+
|
|
79
|
+
app.use(requestLogger());
|
|
80
|
+
|
|
81
|
+
Logs completed HTTP requests.
|
|
82
|
+
|
|
83
|
+
### rateLimiter
|
|
84
|
+
|
|
85
|
+
app.use(rateLimiter({ windowMs: 60000, maxRequests: 100 }));
|
|
86
|
+
|
|
87
|
+
Uses in-memory storage and is intended for single-process applications.
|
|
88
|
+
|
|
89
|
+
### ApiResponse
|
|
90
|
+
|
|
91
|
+
new ApiResponse(200, { id: 1 }, "Success");
|
|
92
|
+
|
|
93
|
+
Creates a standardized API response.
|
|
94
|
+
|
|
95
|
+
### paginate
|
|
96
|
+
|
|
97
|
+
paginate(totalItems, page, limit);
|
|
98
|
+
|
|
99
|
+
Calculates pagination metadata.
|
|
100
|
+
|
|
101
|
+
### validateRequest
|
|
102
|
+
|
|
103
|
+
Validates request body, query, and route parameters using a schema.
|
|
104
|
+
|
|
105
|
+
## Running Tests
|
|
106
|
+
|
|
107
|
+
npm install
|
|
108
|
+
npm test
|
|
109
|
+
npm run check
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
|
114
|
+
wc -l README.md
|
|
115
|
+
head -15 README.md
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-toolkit-pro",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A reusable toolkit for building robust Express.js APIs",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "node --test",
|
|
8
|
+
"check": "node --check src/index.js && npm test"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"express",
|
|
12
|
+
"nodejs",
|
|
13
|
+
"middleware",
|
|
14
|
+
"api",
|
|
15
|
+
"error-handling",
|
|
16
|
+
"pagination",
|
|
17
|
+
"express-toolkit"
|
|
18
|
+
],
|
|
19
|
+
"author": "charan_456",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"type": "commonjs",
|
|
22
|
+
"engines": {
|
|
23
|
+
"node": ">=18"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"express": "^4.22.3"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"express": ">=4.18.0"
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"src",
|
|
33
|
+
"README.md",
|
|
34
|
+
"LICENSE"
|
|
35
|
+
]
|
|
36
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
class ApiError extends Error {
|
|
2
|
+
constructor(
|
|
3
|
+
statusCode,
|
|
4
|
+
message = "Something went wrong",
|
|
5
|
+
errors = [],
|
|
6
|
+
stack = ""
|
|
7
|
+
) {
|
|
8
|
+
if (!Number.isInteger(statusCode) || statusCode < 400 || statusCode > 599) {
|
|
9
|
+
throw new TypeError("statusCode must be an HTTP error status between 400 and 599");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
super(message);
|
|
13
|
+
|
|
14
|
+
this.name = "ApiError";
|
|
15
|
+
this.statusCode = statusCode;
|
|
16
|
+
this.success = false;
|
|
17
|
+
this.errors = errors;
|
|
18
|
+
this.data = null;
|
|
19
|
+
|
|
20
|
+
if (stack) {
|
|
21
|
+
this.stack = stack;
|
|
22
|
+
} else {
|
|
23
|
+
Error.captureStackTrace(this, this.constructor);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = ApiError;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const ApiError = require("./errors/ApiError");
|
|
2
|
+
const asyncHandler = require("./middleware/asyncHandler");
|
|
3
|
+
const errorHandler = require("./middleware/errorHandler");
|
|
4
|
+
const notFound = require("./middleware/notFound");
|
|
5
|
+
const requestLogger = require("./middleware/requestLogger");
|
|
6
|
+
const rateLimiter = require("./middleware/rateLimiter");
|
|
7
|
+
const ApiResponse = require("./utils/ApiResponse");
|
|
8
|
+
const paginate = require("./utils/pagination");
|
|
9
|
+
const validateRequest = require("./validators/validateRequest");
|
|
10
|
+
|
|
11
|
+
module.exports = {
|
|
12
|
+
ApiError,
|
|
13
|
+
asyncHandler,
|
|
14
|
+
errorHandler,
|
|
15
|
+
notFound,
|
|
16
|
+
requestLogger,
|
|
17
|
+
rateLimiter,
|
|
18
|
+
ApiResponse,
|
|
19
|
+
paginate,
|
|
20
|
+
validateRequest
|
|
21
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const errorHandler = (err, req, res, next) => {
|
|
2
|
+
if (res.headersSent) {
|
|
3
|
+
return next(err);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const statusCode =
|
|
7
|
+
Number.isInteger(err.statusCode) &&
|
|
8
|
+
err.statusCode >= 400 &&
|
|
9
|
+
err.statusCode <= 599
|
|
10
|
+
? err.statusCode
|
|
11
|
+
: 500;
|
|
12
|
+
|
|
13
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
14
|
+
|
|
15
|
+
const response = {
|
|
16
|
+
success: false,
|
|
17
|
+
message: isProduction && statusCode >= 500
|
|
18
|
+
? "Internal Server Error"
|
|
19
|
+
: err.message || "Internal Server Error",
|
|
20
|
+
errors: statusCode >= 500 && isProduction
|
|
21
|
+
? []
|
|
22
|
+
: err.errors || []
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
if (!isProduction) {
|
|
26
|
+
response.stack = err.stack;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
res.status(statusCode).json(response);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = errorHandler;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const rateLimiter = (options = {}) => {
|
|
2
|
+
const windowMs = options.windowMs ?? 60_000;
|
|
3
|
+
const maxRequests = options.maxRequests ?? 100;
|
|
4
|
+
const maxKeys = options.maxKeys ?? 10_000;
|
|
5
|
+
|
|
6
|
+
if (!Number.isSafeInteger(windowMs) || windowMs <= 0) {
|
|
7
|
+
throw new TypeError("windowMs must be a positive safe integer");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!Number.isSafeInteger(maxRequests) || maxRequests <= 0) {
|
|
11
|
+
throw new TypeError("maxRequests must be a positive safe integer");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!Number.isSafeInteger(maxKeys) || maxKeys <= 0) {
|
|
15
|
+
throw new TypeError("maxKeys must be a positive safe integer");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const keyGenerator = options.keyGenerator ||
|
|
19
|
+
((req) => req.ip || req.socket?.remoteAddress || "unknown");
|
|
20
|
+
|
|
21
|
+
if (typeof keyGenerator !== "function") {
|
|
22
|
+
throw new TypeError("keyGenerator must be a function");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const message = options.message || "Too many requests";
|
|
26
|
+
const requests = new Map();
|
|
27
|
+
|
|
28
|
+
return (req, res, next) => {
|
|
29
|
+
const now = Date.now();
|
|
30
|
+
const generatedKey = keyGenerator(req);
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
generatedKey === undefined ||
|
|
34
|
+
generatedKey === null ||
|
|
35
|
+
String(generatedKey).trim() === ""
|
|
36
|
+
) {
|
|
37
|
+
return next(new Error("Rate limiter key cannot be empty"));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const key = String(generatedKey);
|
|
41
|
+
|
|
42
|
+
let record = requests.get(key);
|
|
43
|
+
|
|
44
|
+
if (!record || now - record.startTime >= windowMs) {
|
|
45
|
+
record = {
|
|
46
|
+
startTime: now,
|
|
47
|
+
count: 0
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
record.count += 1;
|
|
52
|
+
|
|
53
|
+
// Refresh insertion order for this client.
|
|
54
|
+
requests.delete(key);
|
|
55
|
+
|
|
56
|
+
// Remove expired records.
|
|
57
|
+
for (const [storedKey, storedRecord] of requests) {
|
|
58
|
+
if (now - storedRecord.startTime >= windowMs) {
|
|
59
|
+
requests.delete(storedKey);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Keep storage bounded by evicting the oldest entry.
|
|
64
|
+
if (!requests.has(key) && requests.size >= maxKeys) {
|
|
65
|
+
const oldestKey = requests.keys().next().value;
|
|
66
|
+
requests.delete(oldestKey);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
requests.set(key, record);
|
|
70
|
+
|
|
71
|
+
const remaining = Math.max(0, maxRequests - record.count);
|
|
72
|
+
|
|
73
|
+
const resetSeconds = Math.ceil(
|
|
74
|
+
Math.max(0, windowMs - (now - record.startTime)) / 1000
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
res.setHeader("RateLimit-Limit", maxRequests);
|
|
78
|
+
res.setHeader("RateLimit-Remaining", remaining);
|
|
79
|
+
res.setHeader("RateLimit-Reset", resetSeconds);
|
|
80
|
+
|
|
81
|
+
if (record.count > maxRequests) {
|
|
82
|
+
return res.status(429).json({
|
|
83
|
+
success: false,
|
|
84
|
+
message
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
next();
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
module.exports = rateLimiter;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const requestLogger = (options = {}) => {
|
|
2
|
+
const logger = options.logger || console.log;
|
|
3
|
+
|
|
4
|
+
if (typeof logger !== "function") {
|
|
5
|
+
throw new TypeError("logger must be a function");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return (req, res, next) => {
|
|
9
|
+
const startTime = process.hrtime.bigint();
|
|
10
|
+
|
|
11
|
+
res.on("finish", () => {
|
|
12
|
+
const durationMs =
|
|
13
|
+
Number(process.hrtime.bigint() - startTime) / 1e6;
|
|
14
|
+
|
|
15
|
+
logger({
|
|
16
|
+
method: req.method,
|
|
17
|
+
url: req.originalUrl || req.url,
|
|
18
|
+
statusCode: res.statusCode,
|
|
19
|
+
durationMs: Number(durationMs.toFixed(2))
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
next();
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = requestLogger;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const paginate = (totalItems, page = 1, limit = 10) => {
|
|
2
|
+
const normalizedTotal = Number(totalItems);
|
|
3
|
+
const normalizedPage = Number(page);
|
|
4
|
+
const normalizedLimit = Number(limit);
|
|
5
|
+
|
|
6
|
+
if (!Number.isSafeInteger(normalizedTotal) || normalizedTotal < 0) {
|
|
7
|
+
throw new TypeError("totalItems must be a non-negative safe integer");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (!Number.isSafeInteger(normalizedPage) || normalizedPage < 1) {
|
|
11
|
+
throw new TypeError("page must be a positive safe integer");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!Number.isSafeInteger(normalizedLimit) || normalizedLimit < 1) {
|
|
15
|
+
throw new TypeError("limit must be a positive safe integer");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const offset = (normalizedPage - 1) * normalizedLimit;
|
|
19
|
+
|
|
20
|
+
if (!Number.isSafeInteger(offset)) {
|
|
21
|
+
throw new RangeError("Calculated pagination offset exceeds the safe integer range");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const totalPages = Math.ceil(normalizedTotal / normalizedLimit);
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
totalItems: normalizedTotal,
|
|
28
|
+
currentPage: normalizedPage,
|
|
29
|
+
limit: normalizedLimit,
|
|
30
|
+
totalPages,
|
|
31
|
+
offset,
|
|
32
|
+
hasNextPage: normalizedPage < totalPages,
|
|
33
|
+
hasPreviousPage: normalizedPage > 1
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
module.exports = paginate;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const ApiError = require("../errors/ApiError");
|
|
2
|
+
|
|
3
|
+
const validateRequest = (schema = {}) => {
|
|
4
|
+
const allowedLocations = ["body", "query", "params"];
|
|
5
|
+
|
|
6
|
+
return async (req, res, next) => {
|
|
7
|
+
try {
|
|
8
|
+
const errors = [];
|
|
9
|
+
|
|
10
|
+
for (const location of allowedLocations) {
|
|
11
|
+
const rules = schema[location];
|
|
12
|
+
|
|
13
|
+
if (!rules) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (
|
|
18
|
+
typeof rules !== "object" ||
|
|
19
|
+
rules === null ||
|
|
20
|
+
Array.isArray(rules)
|
|
21
|
+
) {
|
|
22
|
+
throw new TypeError(
|
|
23
|
+
`Validation rules for ${location} must be an object`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const data = req[location] || {};
|
|
28
|
+
|
|
29
|
+
for (const [field, rule] of Object.entries(rules)) {
|
|
30
|
+
if (typeof rule === "function") {
|
|
31
|
+
const result = await rule(data[field], req);
|
|
32
|
+
|
|
33
|
+
if (result !== true && result !== undefined) {
|
|
34
|
+
errors.push({
|
|
35
|
+
location,
|
|
36
|
+
field,
|
|
37
|
+
message: typeof result === "string"
|
|
38
|
+
? result
|
|
39
|
+
: "Invalid value"
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!rule || typeof rule !== "object") {
|
|
47
|
+
throw new TypeError(
|
|
48
|
+
`Invalid validation rule for ${location}.${field}`
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const value = data[field];
|
|
53
|
+
const isMissing =
|
|
54
|
+
value === undefined ||
|
|
55
|
+
value === null ||
|
|
56
|
+
value === "";
|
|
57
|
+
|
|
58
|
+
if (rule.required && isMissing) {
|
|
59
|
+
errors.push({
|
|
60
|
+
location,
|
|
61
|
+
field,
|
|
62
|
+
message: rule.message || `${field} is required`
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (isMissing || !rule.validate) {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (typeof rule.validate !== "function") {
|
|
73
|
+
throw new TypeError(
|
|
74
|
+
`Validator for ${location}.${field} must be a function`
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const result = await rule.validate(value, req);
|
|
79
|
+
|
|
80
|
+
if (result !== true && result !== undefined) {
|
|
81
|
+
errors.push({
|
|
82
|
+
location,
|
|
83
|
+
field,
|
|
84
|
+
message: typeof result === "string"
|
|
85
|
+
? result
|
|
86
|
+
: rule.message || `${field} is invalid`
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (errors.length > 0) {
|
|
93
|
+
return next(
|
|
94
|
+
new ApiError(400, "Request validation failed", errors)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
next();
|
|
99
|
+
} catch (error) {
|
|
100
|
+
next(error);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
module.exports = validateRequest;
|