Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add request to logging output in error middleware #1045

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down