1 import { EmptyObject
} from
'../types/EmptyObject';
2 import { HandleErrorParams
} from
'../types/Error';
3 import Utils from
'./Utils';
4 import chalk from
'chalk';
5 import logger from
'./Logger';
7 export default class FileUtils
{
8 static handleFileException(
12 error
: NodeJS
.ErrnoException
,
13 params
: HandleErrorParams
<EmptyObject
> = { throwError
: true, consoleOut
: false }
15 const prefix
= !Utils
.isEmptyString(logPrefix
) ? logPrefix
+ ' ' : '';
16 if (error
.code
=== 'ENOENT') {
17 if (params
?.consoleOut
) {
19 chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' not found: '),
23 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' not found: %j', error
);
25 } else if (error
.code
=== 'EEXIST') {
26 if (params
?.consoleOut
) {
28 chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' already exists: '),
32 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' already exists: %j', error
);
34 } else if (error
.code
=== 'EACCES') {
35 if (params
?.consoleOut
) {
37 chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' access denied: '),
41 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' access denied: %j', error
);
44 if (params
?.consoleOut
) {
46 chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' error: '),
50 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' error: %j', error
);
52 if (params
?.throwError
) {