0589fa194037a5017fd889e162fca35f6d87de75
1 import chalk from
'chalk';
3 import { logger
} from
'./Logger';
4 import { Utils
} from
'./Utils';
5 import type { EmptyObject
, FileType
, HandleErrorParams
} from
'../types';
7 export class ErrorUtils
{
8 private constructor() {
12 public static handleFileException(
15 error
: NodeJS
.ErrnoException
,
17 params
: HandleErrorParams
<EmptyObject
> = { throwError
: true, consoleOut
: false }
19 const prefix
= Utils
.isNotEmptyString(logPrefix
) ? `${logPrefix} ` : '';
23 logMsg
= `${fileType} file ${file} not found:`;
26 logMsg
= `${fileType} file ${file} already exists:`;
29 logMsg
= `${fileType} file ${file} access denied:`;
32 logMsg
= `${fileType} file ${file} error:`;
34 if (params
?.consoleOut
) {
35 console
.warn(`${chalk.green(prefix)}${chalk.yellow(`${logMsg} `)}`, error);
37 logger.warn(`${prefix}${logMsg}
`, error);
39 if (params?.throwError) {