Skip to content

Commit 1737c89

Browse files
authored
Updates: Added global error handlers (#577)
* Updates: Added global error handlers * comments updated
1 parent 1a4d82d commit 1737c89

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "./polyfill";
22
import { initServer } from "./server";
3+
import { logger } from "./utils/logger";
34
import { initWorker } from "./worker";
45

56
const main = async () => {
@@ -8,3 +9,26 @@ const main = async () => {
89
};
910

1011
main();
12+
13+
// Adding handlers for `uncaughtException` & `unhandledRejection`
14+
// Needs to be root level of your application to ensure it
15+
// catches any unhandledRejections or uncaughtException that occur throughout
16+
// entire codebase
17+
18+
process.on("uncaughtException", (err) => {
19+
logger({
20+
message: "Uncaught Exception",
21+
service: "server",
22+
level: "error",
23+
error: err,
24+
});
25+
});
26+
27+
process.on("unhandledRejection", (err) => {
28+
logger({
29+
message: "Unhandled Rejection",
30+
service: "server",
31+
level: "error",
32+
error: err,
33+
});
34+
});

0 commit comments

Comments
 (0)