Skip to content

Commit

Permalink
feat(*): address PR comments
Browse files Browse the repository at this point in the history
closes #600
  • Loading branch information
aborovsky committed Oct 29, 2024
1 parent 0e143c5 commit 0700a37
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/Utils/ErrorMessageFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0700a37

Please sign in to comment.