Skip to content

Commit

Permalink
fix: update serializeLogData function implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dominictb committed Sep 4, 2024
1 parent bf9b00e commit 876adf8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/libs/Middleware/Logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ function getCircularReplacer() {
};
}

function serializeLoggingData(logData?: Record<string, unknown> | null): Record<string, unknown> | undefined | null {
return logData && (JSON.parse(JSON.stringify(logData, getCircularReplacer())) as Record<string, unknown>);
function serializeLoggingData<T extends Record<string, unknown> | undefined>(logData: T): T | null {
try {
return JSON.parse(JSON.stringify(logData, getCircularReplacer())) as T;
} catch (error) {
Log.hmmm('Failed to serialize log data', {error});
return null;
}
}

function logRequestDetails(message: string, request: Request, response?: Response | void) {
Expand Down

0 comments on commit 876adf8

Please sign in to comment.