powr-sdk-api 1.4.0 → 1.4.1
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.
|
@@ -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) {
|