-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(*): unified error log output (#601)
Closes #600
- Loading branch information
Showing
11 changed files
with
107 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { isAxiosError } from 'axios'; | ||
|
||
type GenericCommandErrorParams = | ||
| { command: string; error: any } | ||
| { message: string; error: unknown }; | ||
|
||
export class ErrorMessageFactory { | ||
public static genericCommandError(params: GenericCommandErrorParams): string { | ||
const message = this.getTitle(params); | ||
const details = this.extractErrorDetails(params); | ||
|
||
return this.formatFinalMessage(message, details); | ||
} | ||
|
||
private static formatFinalMessage( | ||
baseMessage: string, | ||
errorDetails?: string | ||
): string { | ||
return errorDetails | ||
? `${baseMessage}: ${errorDetails}.` | ||
: `${baseMessage}.`; | ||
} | ||
|
||
private static getTitle(params: GenericCommandErrorParams): string { | ||
return 'message' in params | ||
? params.message | ||
: `Error during "${params.command}"`; | ||
} | ||
|
||
private static extractErrorDetails( | ||
params: GenericCommandErrorParams | ||
): string | null { | ||
if (typeof params.error === 'string') { | ||
return params.error; | ||
} | ||
if ( | ||
isAxiosError(params.error) && | ||
typeof params.error.response?.data === 'string' | ||
) { | ||
params.error.response.data; | ||
} | ||
|
||
return (params.error.error || params.error.message) ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters