Refine some logs level.
[e-mobility-charging-stations-simulator.git] / src / utils / FileUtils.ts
CommitLineData
23132a44
JB
1import logger from './Logger';
2
3export default class FileUtils {
4 static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException, consoleOut = false): void {
5 const prefix = logPrefix.length !== 0 ? logPrefix + ' ' : '';
6 if (error.code === 'ENOENT') {
7 if (consoleOut) {
9fbc92f7 8 console.warn(prefix + fileType + ' file ' + filePath + ' not found: ', error);
23132a44 9 } else {
9fbc92f7 10 logger.warn(prefix + fileType + ' file ' + filePath + ' not found: %j', error);
23132a44
JB
11 }
12 } else {
13 if (consoleOut) {
14 console.error(prefix + fileType + ' file ' + filePath + ' opening error: ', error);
15 } else {
16 logger.error(prefix + fileType + ' file ' + filePath + ' opening error: %j', error);
17 }
18 throw error;
19 }
20 }
21}