From 485edbdf4c7b781ac09b08de92764dae4a95e538 Mon Sep 17 00:00:00 2001 From: barri Date: Mon, 8 Jan 2024 18:08:39 +0800 Subject: [PATCH] Fix express server crash --- src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6ac15a0..e4746d1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -245,7 +245,9 @@ async function createHttpServer(listenPort: number) { } } catch (err) { log(`V3 delta error: ${err.message}`); - res.sendStatus(400); + if (!res.headersSent && !res.writableEnded) { + res.sendStatus(400); + } // Remove building file if (buildingFile && fs.existsSync(buildingFile)) fs.rmSync(buildingFile); } @@ -333,7 +335,9 @@ async function createHttpServer(listenPort: number) { } } catch (err) { log(`V2 delta error: ${err.message}`); - res.sendStatus(400); + if (!res.headersSent && !res.writableEnded) { + res.sendStatus(400); + } // Remove building file if (buildingFile && fs.existsSync(buildingFile)) fs.rmSync(buildingFile); }