Don'Ãt exit on errors unless there have been a lot of them recently
This commit is contained in:
parent
34ad8fab8b
commit
dcb00d74f8
1 changed files with 7 additions and 9 deletions
16
src/index.ts
16
src/index.ts
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue