powr-sdk-api 1.4.0 → 1.4.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.
package/dist/index.js CHANGED
@@ -11,6 +11,9 @@ const {
11
11
  validateAuth,
12
12
  generateToken
13
13
  } = require("./middleware/auth");
14
+ const {
15
+ notFoundHandler
16
+ } = require("./middleware/notfound");
14
17
  const createSwaggerSpec = require("./swagger");
15
18
  const logger = require("./logger");
16
19
  module.exports = {
@@ -20,5 +23,6 @@ module.exports = {
20
23
  logger,
21
24
  createSwaggerSpec,
22
25
  generateToken,
23
- validateAuth
26
+ validateAuth,
27
+ notFoundHandler
24
28
  };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ const logger = require("../logger");
4
+ // Handler for 404 Not Found errors
5
+ const notFoundHandler = (req, res) => {
6
+ // Log the 404 error
7
+ logger.warn(`Route not found: ${req.method} ${req.path}`, {
8
+ requestId: req.requestId,
9
+ ip: req.ip,
10
+ userAgent: req.headers['user-agent']
11
+ });
12
+
13
+ // Return a consistent JSON response
14
+ return res.error('The requested resource was not found', 404, `${req.method} ${req.path}`);
15
+ };
16
+ module.exports = {
17
+ notFoundHandler
18
+ };
@@ -141,21 +141,6 @@ const requestHandler = (req, res, next) => {
141
141
  };
142
142
  }
143
143
 
144
- // Add 404 handler to response object if not already present
145
- if (!res.notFound) {
146
- res.notFound = () => {
147
- // Log the 404 error
148
- logger.warn(`Route not found: ${req.method} ${req.path}`, {
149
- requestId: req.requestId,
150
- ip: req.ip,
151
- userAgent: req.headers['user-agent']
152
- });
153
-
154
- // Return a consistent JSON response
155
- return res.error('The requested resource was not found', 404, `${req.method} ${req.path}`);
156
- };
157
- }
158
-
159
144
  // Continue to the next middleware
160
145
  next();
161
146
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-api",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Shared API core library for PowrStack projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",