X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FErrorUtils.ts;h=537aa308b41a0516e4b688c7f9b38124952d455f;hb=42b8cf5cdca8eaab1e7442f7c92c2a5ed97434f6;hp=b4f52ba894a9e57891a04954bbe066b6b1d40ad8;hpb=fa5995d65e5084241af14d0ab7453fbb2fc9d8a6;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/ErrorUtils.ts b/src/utils/ErrorUtils.ts index b4f52ba8..537aa308 100644 --- a/src/utils/ErrorUtils.ts +++ b/src/utils/ErrorUtils.ts @@ -1,7 +1,9 @@ +import process from 'node:process'; + import chalk from 'chalk'; import { logger } from './Logger'; -import { Utils } from './Utils'; +import { isNotEmptyString } from './Utils'; import type { ChargingStation } from '../charging-station'; import type { EmptyObject, @@ -34,10 +36,10 @@ export const handleFileException = ( fileType: FileType, error: NodeJS.ErrnoException, logPrefix: string, - params: HandleErrorParams = defaultErrorParams + params: HandleErrorParams = defaultErrorParams, ): void => { setDefaultErrorParams(params); - const prefix = Utils.isNotEmptyString(logPrefix) ? `${logPrefix} ` : ''; + const prefix = isNotEmptyString(logPrefix) ? `${logPrefix} ` : ''; let logMsg: string; switch (error.code) { case 'ENOENT': @@ -56,10 +58,11 @@ export const handleFileException = ( logMsg = `${fileType} file ${file} error:`; } if (params?.consoleOut === true) { + logMsg = `${logMsg} `; if (params?.throwError) { - console.error(`${chalk.green(prefix)}${chalk.red(`${logMsg} `)}`, error); + console.error(`${chalk.green(prefix)}${chalk.red(logMsg)}`, error); } else { - console.warn(`${chalk.green(prefix)}${chalk.yellow(`${logMsg} `)}`, error); + console.warn(`${chalk.green(prefix)}${chalk.yellow(logMsg)}`, error); } } else if (params?.consoleOut === false) { if (params?.throwError) { @@ -77,7 +80,7 @@ export const handleSendMessageError = ( chargingStation: ChargingStation, commandName: RequestCommand | IncomingRequestCommand, error: Error, - params: HandleErrorParams = { throwError: false, consoleOut: false } + params: HandleErrorParams = { throwError: false, consoleOut: false }, ): void => { setDefaultErrorParams(params, { throwError: false, consoleOut: false }); logger.error(`${chargingStation.logPrefix()} Request command '${commandName}' error:`, error); @@ -88,7 +91,7 @@ export const handleSendMessageError = ( export const setDefaultErrorParams = ( params: HandleErrorParams, - defaultParams: HandleErrorParams = defaultErrorParams + defaultParams: HandleErrorParams = defaultErrorParams, ): HandleErrorParams => { params = { ...defaultParams, ...params }; return params;