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 <eallam@icloud.com>
This commit is contained in:
Liran Tal
2023-08-11 16:18:31 +03:00
committed by GitHub
parent 9dd7fb2748
commit 7daa82fc7a
2 changed files with 16 additions and 8 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@trigger.dev/express": patch
---
fix: avoid crashing the Node.js app on uncaught exceptions
+11 -8
View File
@@ -66,18 +66,21 @@ export function createMiddleware(client: TriggerClient, path: string = "/api/tri
return;
}
const request = convertToStandardRequest(req);
try {
const request = convertToStandardRequest(req);
const response = await client.handleRequest(request);
const response = await client.handleRequest(request);
if (!response) {
res.status(404).json({ error: "Not found" });
if (!response) {
res.status(404).json({ error: "Not found" });
return;
}
return;
}
res.status(response.status).json(response.body);
};
res.status(response.status).json(response.body);
} catch (error) {
next(error)
};
}
function convertToStandardRequest(req: express.Request): StandardRequest {