1 import { EmptyObject
} from
'../types/EmptyObject';
2 import { HandleErrorParams
} from
'../types/Error';
3 import chalk from
'chalk';
4 import logger from
'./Logger';
6 export default class FileUtils
{
7 static handleFileException(
11 error
: NodeJS
.ErrnoException
,
12 params
: HandleErrorParams
<EmptyObject
> = { throwError
: true, consoleOut
: false }
14 const prefix
= logPrefix
.length
!== 0 ? logPrefix
+ ' ' : '';
15 if (error
.code
=== 'ENOENT') {
16 if (params
?.consoleOut
) {
18 chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' not found: '),
22 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' not found: %j', error
);
24 } else if (error
.code
=== 'EEXIST') {
25 if (params
?.consoleOut
) {
27 chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' already exists: '),
31 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' already exists: %j', error
);
33 } else if (error
.code
=== 'EACCES') {
34 if (params
?.consoleOut
) {
36 chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' access denied: '),
40 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' access denied: %j', error
);
43 if (params
?.consoleOut
) {
45 chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' error: '),
49 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' error: %j', error
);
51 if (params
?.throwError
) {