Subscribe to more error events to prevent the process from crashing

This commit is contained in:
Sander Declerck 2025-10-31 09:39:16 +01:00
parent c284ad7ba9
commit 65c9ca62de
No known key found for this signature in database
3 changed files with 44 additions and 12 deletions

View file

@ -43,8 +43,13 @@ export function handleHttpProxyRequest(req, res) {
}
)
.on("error", (err) => {
res.writeHead(502);
res.end(`Bad Gateway: ${err.message}`);
if (!res.headersSent) {
res.writeHead(502);
res.end(`Bad Gateway: ${err.message}`);
} else {
// Headers already sent, just destroy the response
res.destroy();
}
});
req.on("error", () => {