Sfoglia il codice sorgente

Attempt to log httperror

ghorsington 4 anni fa
parent
commit
553ec966cf
1 ha cambiato i file con 8 aggiunte e 1 eliminazioni
  1. 8 1
      bot/src/logging.ts

+ 8 - 1
bot/src/logging.ts

@@ -2,6 +2,7 @@ import winston from "winston";
 import nodemailer from "nodemailer";
 import TransportStream from "winston-transport";
 import Mail from "nodemailer/lib/mailer";
+import { HTTPError } from "got/dist/source";
 
 export const logger = winston.createLogger({
     level: "debug",
@@ -18,8 +19,14 @@ export const logger = winston.createLogger({
     ]
 });
 
+function isHttpError(reason?: unknown): reason is HTTPError {
+    return reason && Object.prototype.hasOwnProperty.call(reason, "request");
+}
+
 process.on("unhandledRejection", (reason) => {
-    throw reason;
+    if (isHttpError(reason))
+        throw new Error(`HTTPError: ${reason.request.requestUrl} failed because ${reason}`);
+    throw new Error(`unhandledRejection: ${reason}`);
 });
 
 interface LogMessage {