From 4c2d2f1c2e9dc0cfe676fa47234670f032cdb16b Mon Sep 17 00:00:00 2001 From: jahabeebs <47253537+jahabeebs@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:40:47 -0500 Subject: [PATCH] fix: pr comments --- .../src/providers/protocolProvider.ts | 4 ++-- packages/shared/src/services/logger.ts | 21 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/automated-dispute/src/providers/protocolProvider.ts b/packages/automated-dispute/src/providers/protocolProvider.ts index d20fc47..452b56a 100644 --- a/packages/automated-dispute/src/providers/protocolProvider.ts +++ b/packages/automated-dispute/src/providers/protocolProvider.ts @@ -257,7 +257,7 @@ export class ProtocolProvider implements IProtocolProvider { url: request.url, method: request.method, headers: Array.from(request.headers.entries()), - body: await request.text(), + body: await request.clone().text(), }; this.logger.debug(`Fetch Request`, reqObject); @@ -267,7 +267,7 @@ export class ProtocolProvider implements IProtocolProvider { url: response.url, status: response.status, headers: Array.from(response.headers.entries()), - body: await response.text(), + body: await response.clone().text(), }; this.logger.debug(`Fetch Response`, respObject); diff --git a/packages/shared/src/services/logger.ts b/packages/shared/src/services/logger.ts index 78c9645..b99b970 100644 --- a/packages/shared/src/services/logger.ts +++ b/packages/shared/src/services/logger.ts @@ -5,8 +5,21 @@ import { ILogger } from "../index.js"; type LogLevel = "error" | "warn" | "info" | "debug"; +type LogEntry = { + timestamp: string; + level: LogLevel; + message: string; + stack?: string; + data?: Record; +}; + const validLogLevels: LogLevel[] = ["error", "warn", "info", "debug"]; +/** + * Logger class that wraps the Winston logger. + * @class Logger + * @implements {ILogger} + */ export class Logger implements ILogger { private logger: WinstonLogger; private static instance: Logger | null; @@ -21,9 +34,9 @@ export class Logger implements ILogger { format.errors({ stack: true }), format((info) => { const { timestamp, level, message, stack, ...meta } = info; - const logEntry: any = { + const logEntry: LogEntry = { timestamp, - level, + level: this.isValidLogLevel(level) ? level : "info", message, }; if (stack) { @@ -51,8 +64,8 @@ export class Logger implements ILogger { return Logger.instance; } - isValidLogLevel(level: any): level is LogLevel { - return validLogLevels.includes(level); + isValidLogLevel(level: string | undefined): level is LogLevel { + return validLogLevels.includes(level as LogLevel); } info(message: string, meta?: unknown) {