Don'Ãt exit on errors unless there have been a lot of them recently

This commit is contained in:
Dragory 2019-01-13 16:52:00 +02:00
parent 34ad8fab8b
commit dcb00d74f8

View file

@ -8,20 +8,18 @@ import { SimpleError } from "./SimpleError";
require("dotenv").config(); require("dotenv").config();
let recentErrors = 0;
const RECENT_ERROR_EXIT_THRESHOLD = 5;
setInterval(() => recentErrors--, 2500);
process.on("unhandledRejection", (reason, p) => { process.on("unhandledRejection", (reason, p) => {
// tslint:disable-next-line
console.error(reason); console.error(reason);
process.exit(1); if (++recentErrors >= RECENT_ERROR_EXIT_THRESHOLD) process.exit(1);
}); });
process.on("uncaughtException", err => { process.on("uncaughtException", err => {
if (err.message && err.message.startsWith("DiscordHTTPError")) { console.error(err);
console.error(err); if (++recentErrors >= RECENT_ERROR_EXIT_THRESHOLD) process.exit(1);
return;
} else {
console.error(err);
process.exit(1);
}
}); });
// Verify required Node.js version // Verify required Node.js version