use got instead of axios, some cleanup, problem with async context being lost for...
[websub-hub] / src / service.js
index b49882989e7544e40a5f368f3f7dcd8a133c9487..d77d06c7794819967478df957afe0cfea7e0bbee 100644 (file)
@@ -72,12 +72,19 @@ class Service extends Dingus {
 
   /**
    * Rearrange logging data.
+   * @param {http.ClientRequest} req
+   * @param {http.ServerResponse} res
+   * @param {Object} ctx
    */
   async preHandler(req, res, ctx) {
     await super.preHandler(req, res, ctx);
     const logObject = this.asyncLocalStorage.getStore();
-    logObject.requestId = ctx.requestId;
-    delete ctx.requestId;
+    // FIXME: for some reason, returning from the super.preHandler loses async context?
+    // Workaround until cause and solution are found.
+    if (logObject) {
+      logObject.requestId = ctx.requestId;
+      delete ctx.requestId;
+    }
   }