Skip to content

Commit 7daa82f

Browse files
lirantalericallam
andauthored
fix: avoid crashing the Node.js app on uncaught exceptions (#307)
* fix: avoid crashing the Node.js app on uncaught exceptions * Create smooth-dodos-obey.md --------- Co-authored-by: Eric Allam <[email protected]>
1 parent 9dd7fb2 commit 7daa82f

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

.changeset/smooth-dodos-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@trigger.dev/express": patch
3+
---
4+
5+
fix: avoid crashing the Node.js app on uncaught exceptions

packages/express/src/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,21 @@ export function createMiddleware(client: TriggerClient, path: string = "/api/tri
6666
return;
6767
}
6868

69-
const request = convertToStandardRequest(req);
69+
try {
70+
const request = convertToStandardRequest(req);
7071

71-
const response = await client.handleRequest(request);
72+
const response = await client.handleRequest(request);
7273

73-
if (!response) {
74-
res.status(404).json({ error: "Not found" });
74+
if (!response) {
75+
res.status(404).json({ error: "Not found" });
7576

76-
return;
77-
}
77+
return;
78+
}
7879

79-
res.status(response.status).json(response.body);
80-
};
80+
res.status(response.status).json(response.body);
81+
} catch (error) {
82+
next(error)
83+
};
8184
}
8285

8386
function convertToStandardRequest(req: express.Request): StandardRequest {

0 commit comments

Comments
 (0)