From dcb00d74f867d01e32de05706a3672b264856a25 Mon Sep 17 00:00:00 2001 From: Dragory Date: Sun, 13 Jan 2019 16:52:00 +0200 Subject: [PATCH] =?UTF-8?q?Don'=C3=83t=20exit=20on=20errors=20unless=20the?= =?UTF-8?q?re=20have=20been=20a=20lot=20of=20them=20recently?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 0fd6394a..90b840f3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,20 +8,18 @@ import { SimpleError } from "./SimpleError"; require("dotenv").config(); +let recentErrors = 0; +const RECENT_ERROR_EXIT_THRESHOLD = 5; +setInterval(() => recentErrors--, 2500); + process.on("unhandledRejection", (reason, p) => { - // tslint:disable-next-line console.error(reason); - process.exit(1); + if (++recentErrors >= RECENT_ERROR_EXIT_THRESHOLD) process.exit(1); }); process.on("uncaughtException", err => { - if (err.message && err.message.startsWith("DiscordHTTPError")) { - console.error(err); - return; - } else { - console.error(err); - process.exit(1); - } + console.error(err); + if (++recentErrors >= RECENT_ERROR_EXIT_THRESHOLD) process.exit(1); }); // Verify required Node.js version