1 import { HandleErrorParams
} from
'../types/Error';
2 import chalk from
'chalk';
3 import logger from
'./Logger';
5 export default class FileUtils
{
6 static handleFileException(logPrefix
: string, fileType
: string, filePath
: string, error
: NodeJS
.ErrnoException
,
7 params
: HandleErrorParams
= { throwError
: true, consoleOut
: false }): void {
8 const prefix
= logPrefix
.length
!== 0 ? logPrefix
+ ' ' : '';
9 if (error
.code
=== 'ENOENT') {
10 if (params
?.consoleOut
) {
11 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' not found: '), error
);
13 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' not found: %j', error
);
15 } else if (error
.code
=== 'EEXIST') {
16 if (params
?.consoleOut
) {
17 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' already exists: '), error
);
19 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' already exists: %j', error
);
21 } else if (error
.code
=== 'EACCES') {
22 if (params
?.consoleOut
) {
23 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' access denied: '), error
);
25 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' access denied: %j', error
);
28 if (params
?.consoleOut
) {
29 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' error: '), error
);
31 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' error: %j', error
);
33 if (params
?.throwError
) {