usetraceforge 0.1.16 → 0.1.17
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/express.d.ts +1 -1
- package/dist/express.js +22 -20
- package/package.json +1 -1
package/dist/express.d.ts
CHANGED
|
@@ -3,4 +3,4 @@ import { Request, Response, NextFunction } from "express";
|
|
|
3
3
|
* Express middleware to catch unhandled errors and report them to TraceForge.
|
|
4
4
|
* Ensure this is added AFTER all your routes and controllers, but BEFORE your custom error handler.
|
|
5
5
|
*/
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const expressErrorHandler: () => (error: Error, req: Request, res: Response, next: NextFunction) => void;
|
package/dist/express.js
CHANGED
|
@@ -3,25 +3,27 @@ import TraceForge from "./index.js";
|
|
|
3
3
|
* Express middleware to catch unhandled errors and report them to TraceForge.
|
|
4
4
|
* Ensure this is added AFTER all your routes and controllers, but BEFORE your custom error handler.
|
|
5
5
|
*/
|
|
6
|
-
export const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
export const expressErrorHandler = () => {
|
|
7
|
+
return (error, req, res, next) => {
|
|
8
|
+
TraceForge.captureException(error, {
|
|
9
|
+
environment: "node",
|
|
10
|
+
tags: {
|
|
11
|
+
method: req.method,
|
|
12
|
+
url: req.url,
|
|
13
|
+
path: req.path,
|
|
14
|
+
ip: req.ip || "Unknown"
|
|
15
|
+
},
|
|
16
|
+
payload: {
|
|
17
|
+
query: req.query,
|
|
18
|
+
body: req.body,
|
|
19
|
+
headers: {
|
|
20
|
+
...req.headers,
|
|
21
|
+
authorization: req.headers.authorization ? "[REDACTED]" : undefined,
|
|
22
|
+
cookie: req.headers.cookie ? "[REDACTED]" : undefined
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
}).catch(() => undefined);
|
|
26
|
+
// Pass the error to the next error handler
|
|
27
|
+
next(error);
|
|
28
|
+
};
|
|
27
29
|
};
|