From 8fcb793896abe9c029d40f88f4cf7b22aa8e5e01 Mon Sep 17 00:00:00 2001
From: danoswaltCL <97542869+danoswaltCL@users.noreply.github.com>
Date: Mon, 9 Oct 2023 10:33:28 -0400
Subject: [PATCH] add request to logging output in error middleware

---
 .../src/api/middlewares/ErrorHandlerMiddleware.ts  | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/backend/packages/Upgrade/src/api/middlewares/ErrorHandlerMiddleware.ts b/backend/packages/Upgrade/src/api/middlewares/ErrorHandlerMiddleware.ts
index 867301610f..40931261de 100644
--- a/backend/packages/Upgrade/src/api/middlewares/ErrorHandlerMiddleware.ts
+++ b/backend/packages/Upgrade/src/api/middlewares/ErrorHandlerMiddleware.ts
@@ -6,6 +6,12 @@ import { ErrorService } from '../services/ErrorService';
 import { ExperimentError } from '../models/ExperimentError';
 import { SERVER_ERROR } from 'upgrade_types';
 
+interface ErrorWithRequest extends ExperimentError {
+  request?: {
+    [key: string]: any;
+  };
+}
+
 @Middleware({ type: 'after' })
 export class ErrorHandlerMiddleware implements ExpressErrorMiddlewareInterface {
   public isProduction = env.isProduction;
@@ -93,7 +99,7 @@ export class ErrorHandlerMiddleware implements ExpressErrorMiddlewareInterface {
             break;
           case 422:
             message = error.message;
-            type = SERVER_ERROR.UNSUPPORTED_CALIPER
+            type = SERVER_ERROR.UNSUPPORTED_CALIPER;
             break;
           default:
             message = error.message;
@@ -103,12 +109,16 @@ export class ErrorHandlerMiddleware implements ExpressErrorMiddlewareInterface {
     }
 
     // making error document
-    const experimentError = new ExperimentError();
+    const experimentError: ErrorWithRequest = new ExperimentError();
     experimentError.name = error.name;
     experimentError.message = message;
     experimentError.endPoint = req.originalUrl;
     experimentError.errorCode = error.httpCode;
     experimentError.type = type;
+
+    // #1042 send request in logging output, don't need to put into database
+    experimentError.request = req.body;
+
     req.logger.error(experimentError);
     experimentError.type ? await this.errorService.create(experimentError, req.logger) : await Promise.resolve(error);
     if (!res.headersSent) {