import { ChargingStationWorkerData, ChargingStationWorkerMessage, ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker';
import Configuration from '../utils/Configuration';
+import { StationTemplateUrl } from '../types/ConfigurationData';
import Statistics from '../types/Statistics';
import { Storage } from '../performance/storage/Storage';
import { StorageFactory } from '../performance/storage/StorageFactory';
try {
const nbStations = stationTemplateUrl.numberOfStations ?? 0;
for (let index = 1; index <= nbStations; index++) {
- const workerData: ChargingStationWorkerData = {
- index,
- templateFile: path.join(path.resolve(__dirname, '../'), 'assets', 'station-templates', path.basename(stationTemplateUrl.file))
- };
- await this.workerImplementation.addElement(workerData);
- this.numberOfChargingStations++;
+ await this.startChargingStation(index, stationTemplateUrl);
}
} catch (error) {
console.error(chalk.red('Charging station start with template file ' + stationTemplateUrl.file + ' error '), error);
});
}
+ private async startChargingStation(index: number, stationTemplateUrl: StationTemplateUrl): Promise<void> {
+ const workerData: ChargingStationWorkerData = {
+ index,
+ templateFile: path.join(path.resolve(__dirname, '../'), 'assets', 'station-templates', path.basename(stationTemplateUrl.file))
+ };
+ await this.workerImplementation.addElement(workerData);
+ this.numberOfChargingStations++;
+ }
+
private logPrefix(): string {
return Utils.logPrefix(' Bootstrap |');
}
if (ftpClient) {
ftpClient.close();
}
- return this.handleIncomingRequestError(OCPP16IncomingRequestCommand.GET_DIAGNOSTICS, error as Error, Constants.OCPP_RESPONSE_EMPTY);
+ return this.handleIncomingRequestError(OCPP16IncomingRequestCommand.GET_DIAGNOSTICS, error as Error, { errorResponse: Constants.OCPP_RESPONSE_EMPTY });
}
} else {
logger.error(`${this.chargingStation.logPrefix()} Unsupported protocol ${uri.protocol} to transfer the diagnostic logs archive`);
return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
}
} catch (error) {
- return this.handleIncomingRequestError(OCPP16IncomingRequestCommand.TRIGGER_MESSAGE, error as Error, Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED);
+ return this.handleIncomingRequestError(OCPP16IncomingRequestCommand.TRIGGER_MESSAGE, error as Error, { errorResponse: Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_REJECTED });
}
}
}
return OCPPIncomingRequestService.instances.get(chargingStation.id) as T;
}
- protected handleIncomingRequestError<T>(commandName: IncomingRequestCommand, error: Error, errorOcppResponse?: T, params: HandleErrorParams = { throwError: true }): T {
+ protected handleIncomingRequestError<T>(commandName: IncomingRequestCommand, error: Error, params: HandleErrorParams<T> = { throwError: true }): T {
logger.error(this.chargingStation.logPrefix() + ' Incoming request command %s error: %j', commandName, error);
- if (errorOcppResponse) {
- return errorOcppResponse;
+ if (!params?.throwError && params?.errorResponse) {
+ return params?.errorResponse;
}
- if (params?.throwError) {
+ if (params?.throwError && !params?.errorResponse) {
throw error;
}
+ if (params?.throwError && params?.errorResponse) {
+ return params?.errorResponse;
+ }
}
public abstract handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload: JsonType): Promise<void>;
import { DBName, StorageType } from '../../types/Storage';
+import { EmptyObject } from '../../types/EmptyObject';
import { HandleErrorParams } from '../../types/Error';
import Statistics from '../../types/Statistics';
import { URL } from 'url';
this.logPrefix = logPrefix;
}
- protected handleDBError(type: StorageType, error: Error, table?: string, params: HandleErrorParams = { throwError: false }): void {
+ protected handleDBError(type: StorageType, error: Error, table?: string, params: HandleErrorParams<EmptyObject> = { throwError: false }): void {
logger.error(`${this.logPrefix} ${this.getDBNameFromStorageType(type)} error '${error.message}'${(!Utils.isNullOrUndefined(table) || !table) && ` in table or collection '${table}'`}: %j`, error);
if (params?.throwError) {
throw error;
-export interface HandleErrorParams {
+export interface HandleErrorParams<T> {
throwError?: boolean;
consoleOut?: boolean;
+ errorResponse?: T;
}
import ConfigurationData, { StationTemplateUrl, StorageConfiguration, SupervisionUrlDistribution, UIWebSocketServerConfiguration } from '../types/ConfigurationData';
import Constants from './Constants';
+import { EmptyObject } from '../types/EmptyObject';
import { HandleErrorParams } from '../types/Error';
import { ServerOptions } from 'ws';
import { StorageType } from '../types/Storage';
return typeof obj === 'undefined';
}
- private static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException, params: HandleErrorParams = { throwError: true }): void {
+ private static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException,
+ params: HandleErrorParams<EmptyObject> = { throwError: true }): void {
const prefix = logPrefix.length !== 0 ? logPrefix + ' ' : '';
if (error.code === 'ENOENT') {
console.error(chalk.green(prefix) + chalk.red(fileType + ' file ' + filePath + ' not found: '), error);
+import { EmptyObject } from '../types/EmptyObject';
import { HandleErrorParams } from '../types/Error';
import chalk from 'chalk';
import logger from './Logger';
export default class FileUtils {
static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException,
- params: HandleErrorParams = { throwError: true, consoleOut: false }): void {
+ params: HandleErrorParams<EmptyObject> = { throwError: true, consoleOut: false }): void {
const prefix = logPrefix.length !== 0 ? logPrefix + ' ' : '';
if (error.code === 'ENOENT') {
if (params?.consoleOut) {