import type ChargingStation from '../ChargingStation';
+import { HandleErrorParams } from '../../types/Error';
import { IncomingRequestCommand } from '../../types/ocpp/Requests';
import { JsonType } from '../../types/JsonType';
import logger from '../../utils/Logger';
return OCPPIncomingRequestService.instances.get(chargingStation.id) as T;
}
- protected handleIncomingRequestError<T>(commandName: IncomingRequestCommand, error: Error, errorOcppResponse?: T): T {
+ protected handleIncomingRequestError<T>(commandName: IncomingRequestCommand, error: Error, errorOcppResponse?: T, params: HandleErrorParams = { throwError: true }): T {
logger.error(this.chargingStation.logPrefix() + ' Incoming request command %s error: %j', commandName, error);
if (errorOcppResponse) {
return errorOcppResponse;
}
- throw error;
+ if (params?.throwError) {
+ throw error;
+ }
}
public abstract handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload: JsonType): Promise<void>;
import type ChargingStation from '../ChargingStation';
import Constants from '../../utils/Constants';
import { ErrorType } from '../../types/ocpp/ErrorType';
+import { HandleErrorParams } from '../../types/Error';
import { JsonType } from '../../types/JsonType';
import { MessageType } from '../../types/ocpp/MessageType';
import { MeterValue } from '../../types/ocpp/MeterValues';
try {
return await this.internalSendMessage(messageId, messagePayload, MessageType.CALL_MESSAGE, commandName, params);
} catch (error) {
- this.handleRequestError(commandName, error as Error);
+ this.handleRequestError(commandName, error as Error, { throwError: false });
}
}
return messageToSend;
}
- private handleRequestError(commandName: RequestCommand | IncomingRequestCommand, error: Error): void {
+ private handleRequestError(commandName: RequestCommand | IncomingRequestCommand, error: Error, params: HandleErrorParams = { throwError: true }): void {
logger.error(this.chargingStation.logPrefix() + ' Request command %s error: %j', commandName, error);
- throw error;
+ if (params?.throwError) {
+ throw error;
+ }
}
public abstract sendHeartbeat(params?: SendParams): Promise<void>;
import { DBName, StorageType } from '../../types/Storage';
+import { HandleErrorParams } from '../../types/Error';
import Statistics from '../../types/Statistics';
import { URL } from 'url';
import Utils from '../../utils/Utils';
this.logPrefix = logPrefix;
}
- protected handleDBError(type: StorageType, error: Error, table?: string): void {
+ protected handleDBError(type: StorageType, error: Error, table?: string, params: HandleErrorParams = { 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;
+ }
}
protected getDBNameFromStorageType(type: StorageType): DBName {
--- /dev/null
+export interface HandleErrorParams {
+ throwError?: boolean;
+ consoleOut?: boolean;
+}
import ConfigurationData, { StationTemplateUrl, StorageConfiguration, SupervisionUrlDistribution, UIWebSocketServerConfiguration } from '../types/ConfigurationData';
import Constants from './Constants';
+import { HandleErrorParams } from '../types/Error';
import { ServerOptions } from 'ws';
import { StorageType } from '../types/Storage';
import type { WorkerChoiceStrategy } from 'poolifier';
return typeof obj === 'undefined';
}
- private static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException): void {
+ private static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException, params: HandleErrorParams = { 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);
} else {
console.error(chalk.green(prefix) + chalk.red(fileType + ' file ' + filePath + ' error: '), error);
}
- throw error;
+ if (params?.throwError) {
+ throw error;
+ }
}
}
+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, consoleOut = false): void {
+ static handleFileException(logPrefix: string, fileType: string, filePath: string, error: NodeJS.ErrnoException,
+ params: HandleErrorParams = { throwError: true, consoleOut: false }): void {
const prefix = logPrefix.length !== 0 ? logPrefix + ' ' : '';
if (error.code === 'ENOENT') {
- if (consoleOut) {
+ if (params?.consoleOut) {
console.warn(chalk.green(prefix) + chalk.yellow(fileType + ' file ' + filePath + ' not found: '), error);
} else {
logger.warn(prefix + fileType + ' file ' + filePath + ' not found: %j', error);
}
} else if (error.code === 'EEXIST') {
- if (consoleOut) {
+ if (params?.consoleOut) {
console.warn(chalk.green(prefix) + chalk.yellow(fileType + ' file ' + filePath + ' already exists: '), error);
} else {
logger.warn(prefix + fileType + ' file ' + filePath + ' already exists: %j', error);
}
} else if (error.code === 'EACCES') {
- if (consoleOut) {
+ if (params?.consoleOut) {
console.warn(chalk.green(prefix) + chalk.yellow(fileType + ' file ' + filePath + ' access denied: '), error);
} else {
logger.warn(prefix + fileType + ' file ' + filePath + ' access denied: %j', error);
}
} else {
- if (consoleOut) {
+ if (params?.consoleOut) {
console.warn(chalk.green(prefix) + chalk.yellow(fileType + ' file ' + filePath + ' error: '), error);
} else {
logger.warn(prefix + fileType + ' file ' + filePath + ' error: %j', error);
}
- throw error;
+ if (params?.throwError) {
+ throw error;
+ }
}
}
}