| 1 | import logger from './Logger'; |
| 2 | |
| 3 | export 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) { |
| 8 | console.warn(prefix + fileType + ' file ' + filePath + ' not found: ', error); |
| 9 | } else { |
| 10 | logger.warn(prefix + fileType + ' file ' + filePath + ' not found: %j', error); |
| 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 | } |