error as Error,
{
errorResponse: OCPP16Constants.OCPP_CANCEL_RESERVATION_RESPONSE_REJECTED,
+ throwError: false,
}
)!
}
chargingStation,
OCPP16IncomingRequestCommand.DATA_TRANSFER,
error as Error,
- { errorResponse: OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED }
+ { errorResponse: OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED, throwError: false }
)!
}
}
chargingStation,
OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
error as Error,
- { errorResponse: OCPP16Constants.OCPP_RESPONSE_EMPTY }
+ { errorResponse: OCPP16Constants.OCPP_RESPONSE_EMPTY, throwError: false }
)!
}
} else {
chargingStation,
OCPP16IncomingRequestCommand.RESERVE_NOW,
error as Error,
- { errorResponse: OCPP16Constants.OCPP_RESERVATION_RESPONSE_FAULTED }
+ { errorResponse: OCPP16Constants.OCPP_RESERVATION_RESPONSE_FAULTED, throwError: false }
)!
}
}
export const handleUncaughtException = (): void => {
process.on('uncaughtException', (error: Error) => {
console.error(chalk.red('Uncaught exception: '), error)
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+ logger?.error?.('Uncaught exception:', error)
})
}
export const handleUnhandledRejection = (): void => {
- process.on('unhandledRejection', (reason: unknown) => {
- console.error(chalk.red('Unhandled rejection: '), reason)
+ process.on('unhandledRejection', (reason: unknown, promise: Promise<unknown>) => {
+ console.error(chalk.red('Unhandled rejection: '), { promise, reason })
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
+ logger?.error?.('Unhandled rejection:', { promise, reason })
})
}
case 'EEXIST':
logMsg = `${fileType} file ${file} already exists:`
break
+ case 'EISDIR':
+ logMsg = `${fileType} file ${file} is a directory:`
+ break
case 'ENOENT':
logMsg = `${fileType} file ${file} not found:`
break
+ case 'ENOSPC':
+ logMsg = `${fileType} file ${file} no space left on device:`
+ break
+ case 'ENOTDIR':
+ logMsg = `${fileType} file ${file} parent is not a directory:`
+ break
case 'EPERM':
logMsg = `${fileType} file ${file} permission denied:`
break
+ case 'EROFS':
+ logMsg = `${fileType} file ${file} read-only file system:`
+ break
default:
logMsg = `${fileType} file ${file} error:`
}
},
...params,
}
- logger.error(
- `${chargingStation.logPrefix()} ${moduleName}.handleSendMessageError: Send ${getMessageTypeString(messageType)} command '${commandName}' error:`,
- error
- )
+ const logMsg = `${chargingStation.logPrefix()} ${moduleName}.handleSendMessageError: Send ${getMessageTypeString(messageType)} command '${commandName}' error:`
+ if (params.consoleOut === true) {
+ console.error(logMsg, error)
+ } else {
+ logger.error(logMsg, error)
+ }
if (params.throwError === true) {
throw error
}
},
...params,
}
- logger.error(
- `${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`,
- error
- )
- if (params.throwError === false && params.errorResponse != null) {
- return params.errorResponse
- }
- if (params.throwError === true && params.errorResponse == null) {
- throw error
+ const logMsg = `${chargingStation.logPrefix()} ${moduleName}.handleIncomingRequestError: Incoming request command '${commandName}' error:`
+ if (params.consoleOut === true) {
+ console.error(logMsg, error)
+ } else {
+ logger.error(logMsg, error)
}
- if (params.throwError === true && params.errorResponse != null) {
+ if (params.throwError === false) {
return params.errorResponse
}
+ throw error
}