From 0700a37b245a3e8dce06fa04c173668fe69bddcc Mon Sep 17 00:00:00 2001 From: Aleksandr Borovskii Date: Tue, 29 Oct 2024 11:36:46 +0100 Subject: [PATCH] feat(*): address PR comments closes #600 --- src/Utils/ErrorMessageFactory.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Utils/ErrorMessageFactory.ts b/src/Utils/ErrorMessageFactory.ts index 325d5ac8..9a4fc59d 100644 --- a/src/Utils/ErrorMessageFactory.ts +++ b/src/Utils/ErrorMessageFactory.ts @@ -5,28 +5,30 @@ type GenericCommandErrorParams = | { message: string; error: unknown }; export class ErrorMessageFactory { - public static genericCommandError(params: GenericCommandErrorParam): string { + public static genericCommandError(params: GenericCommandErrorParams): string { const message = this.getMessageTitle(params); - const details = this.getMessageDetails(params); + const details = this.extractErrorDetails(params); return this.formatFinalMessage(message, details); } - - private static formatFinalMessage(baseMessage: string, errorDetails?: string): string { - return errorDetails + + private static formatFinalMessage( + baseMessage: string, + errorDetails?: string + ): string { + return errorDetails ? `${baseMessage}: ${errorDetails}.` : `${baseMessage}.`; } - } - private static getMessageTitle(params: GenericCommandErrorParam): string { + private static getMessageTitle(params: GenericCommandErrorParams): string { return 'message' in params ? params.message : `Error during "${params.command}"`; } private static extractErrorDetails( - params: GenericCommandErrorParam + params: GenericCommandErrorParams ): string | null { if (typeof params.error === 'string') { return params.error;