014ebbdece21cf9a3c9b512573faf95c741693f1
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(logPrefix
: string, fileType
: string, filePath
: string, error
: NodeJS
.ErrnoException
,
8 params
: HandleErrorParams
<EmptyObject
> = { throwError
: true, consoleOut
: false }): void {
9 const prefix
= logPrefix
.length
!== 0 ? logPrefix
+ ' ' : '';
10 if (error
.code
=== 'ENOENT') {
11 if (params
?.consoleOut
) {
12 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' not found: '), error
);
14 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' not found: %j', error
);
16 } else if (error
.code
=== 'EEXIST') {
17 if (params
?.consoleOut
) {
18 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' already exists: '), error
);
20 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' already exists: %j', error
);
22 } else if (error
.code
=== 'EACCES') {
23 if (params
?.consoleOut
) {
24 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' access denied: '), error
);
26 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' access denied: %j', error
);
29 if (params
?.consoleOut
) {
30 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' error: '), error
);
32 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' error: %j', error
);
34 if (params
?.throwError
) {