From 2cf012e6a0c823f822bdd7345ea667ada34d1c96 Mon Sep 17 00:00:00 2001 From: Guillaume Villerez Date: Fri, 2 Jul 2021 19:17:38 +0200 Subject: [PATCH] Better error handling --- src/server.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/server.ts b/src/server.ts index 3f6c4ec..771f3e7 100644 --- a/src/server.ts +++ b/src/server.ts @@ -99,6 +99,11 @@ export class StaticServer extends TypedEmitter { this.server = http.createServer((req, res) => this.handleRequest(req, res)) this.terminator = createHttpTerminator({ server: this.server }) + this.server.on('error', e => { + this.emit('failure', e) + this.stop() + }) + this.server.listen(this.port, this.host, () => { this.emit('start', this.host, this.port, this.source) })