Forráskód Böngészése

Print stack trace when needed

ghorsington 4 éve
szülő
commit
367e125ab5
1 módosított fájl, 5 hozzáadás és 3 törlés
  1. 5 3
      bot/src/logging.ts

+ 5 - 3
bot/src/logging.ts

@@ -2,7 +2,7 @@ import winston from "winston";
 import nodemailer from "nodemailer";
 import TransportStream from "winston-transport";
 import Mail from "nodemailer/lib/mailer";
-import { isHttpError } from "./util";
+import { isHttpError, hasStackTrace } from "./util";
 
 export const logger = winston.createLogger({
     level: "debug",
@@ -22,8 +22,10 @@ export const logger = winston.createLogger({
 
 process.on("unhandledRejection", (reason) => {
     if (isHttpError(reason))
-        throw new Error(`HTTPError: ${reason.request.requestUrl} failed because ${reason}`);
-    throw new Error(`unhandledRejection: ${reason}`);
+        throw new Error(`HTTPError: ${reason.request.requestUrl} failed because ${reason}\nStack trace: ${reason.stack}`);
+    if (hasStackTrace(reason))
+        throw new Error(`Unhandled rejection: ${reason}\nFull stack trace: ${reason.stack}`);
+    throw new Error(`Unhandled rejection: ${reason}`);
 });
 
 interface LogMessage {