powr-sdk-api 2.3.0 → 2.3.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.
- package/dist/middleware/error.js +18 -2
- package/dist/middleware/notfound.js +13 -2
- package/package.json +1 -1
package/dist/middleware/error.js
CHANGED
|
@@ -15,8 +15,24 @@ const errorHandler = (err, req, res, next) => {
|
|
|
15
15
|
const message = err.message || 'Internal Server Error';
|
|
16
16
|
const statusCode = err.statusCode || 500;
|
|
17
17
|
|
|
18
|
-
//
|
|
19
|
-
|
|
18
|
+
// Check if res.error is available (from requestHandler)
|
|
19
|
+
if (res.error) {
|
|
20
|
+
return res.error(message, statusCode, err);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Fallback error handling if res.error is not available
|
|
24
|
+
console.error('Error:', err);
|
|
25
|
+
const response = {
|
|
26
|
+
success: false,
|
|
27
|
+
message: message,
|
|
28
|
+
requestId: req.requestId || 'unknown'
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Include error details in development
|
|
32
|
+
if (process.env.NODE_ENV === 'development') {
|
|
33
|
+
response.error = err.stack;
|
|
34
|
+
}
|
|
35
|
+
return res.status(statusCode).json(response);
|
|
20
36
|
};
|
|
21
37
|
module.exports = {
|
|
22
38
|
errorCatcher,
|
|
@@ -10,8 +10,19 @@ const notFoundHandler = (req, res) => {
|
|
|
10
10
|
userAgent: req.headers['user-agent']
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
//
|
|
14
|
-
|
|
13
|
+
// Check if res.error is available (from requestHandler)
|
|
14
|
+
if (res.error) {
|
|
15
|
+
return res.error('The requested resource was not found', 404, `${req.method} ${req.path}`);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Fallback 404 handling if res.error is not available
|
|
19
|
+
const response = {
|
|
20
|
+
success: false,
|
|
21
|
+
message: 'The requested resource was not found',
|
|
22
|
+
requestId: req.requestId || 'unknown',
|
|
23
|
+
path: `${req.method} ${req.path}`
|
|
24
|
+
};
|
|
25
|
+
return res.status(404).json(response);
|
|
15
26
|
};
|
|
16
27
|
module.exports = {
|
|
17
28
|
notFoundHandler
|