Browse Source

Print deep object on fail

ghorsington 4 years ago
parent
commit
874927fc74
1 changed files with 9 additions and 1 deletions
  1. 9 1
      bot/src/logging.ts

+ 9 - 1
bot/src/logging.ts

@@ -3,6 +3,7 @@ import nodemailer from "nodemailer";
 import TransportStream from "winston-transport";
 import Mail from "nodemailer/lib/mailer";
 import { isHttpError, hasStackTrace } from "./util";
+import { inspect } from "util";
 
 export const logger = winston.createLogger({
     level: "debug",
@@ -21,11 +22,18 @@ export const logger = winston.createLogger({
 });
 
 process.on("unhandledRejection", (reason) => {
+    
     if (isHttpError(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}`);
+    let contents = `${reason}`;
+    try {
+        contents = inspect(reason, true);
+    } catch (e) { 
+        // ignored
+    }
+    throw new Error(`Unhandled rejection: ${contents}`); 
 });
 
 interface LogMessage {