From a188b0433c5344f9e22b048a6283b6b00139f3f3 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 4 Aug 2019 15:45:35 +0300 Subject: [PATCH] api: crash on unhandled rejections --- src/api/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/api/index.ts b/src/api/index.ts index 113d8990..8daeda13 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -7,9 +7,19 @@ import { initArchives } from "./archives"; import { connect } from "../data/db"; import path from "path"; import { TokenError } from "passport-oauth2"; +import { PluginError } from "knub"; require("dotenv").config({ path: path.resolve(__dirname, "..", "..", "api.env") }); +function errorHandler(err) { + // tslint:disable:no-console + console.error(err.stack || err); + process.exit(1); + // tslint:enable:no-console +} + +process.on("unhandledRejection", errorHandler); + console.log("Connecting to database..."); connect().then(() => { const app = express();