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) {