Bypass Charging Station in error when not in prod env
MODIFY
src/client/ocpp/json/JsonRestChargingStationClient.ts
src/client/ocpp/json/JsonRestChargingStationClient.ts
@@ -6,6 +6,7 @@ import ChargingStationClient from '../ChargingStationClient';
import Configuration from '../../../utils/Configuration';
import Logging from '../../../utils/Logging';
import { ServerAction } from '../../../types/Server';
+import Utils from '../../../utils/Utils';
import WSClient from '../../websocket/WSClient';
import { v4 as uuid } from 'uuid';
@@ -132,6 +133,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
};
// Closed
this.wsConnection.onclose = () => {
+ if (Utils.isProductionEnv()) {
// Log
Logging.logInfo({
tenantID: this.tenantID,
@@ -140,9 +142,11 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
module: MODULE_NAME, method: 'onClose',
message: `Connection closed from '${this.serverURL}'`
});
+ }
};
// Handle Error Message
this.wsConnection.onerror = (error) => {
+ if (Utils.isProductionEnv()) {
// Log
Logging.logException(
error,
@@ -151,6 +155,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
MODULE_NAME, 'onError',
this.tenantID
);
+ }
// Terminate WS in error
this.terminateConnection();
};

MODIFY
src/client/websocket/WSClient.ts
src/client/websocket/WSClient.ts
@@ -219,6 +219,7 @@ export default class WSClient {
break;
default:
if (this.dbLogging) {
+ if (Utils.isProductionEnv()) {
// Error message
Logging.logError({
tenantID: this.logTenantID,
@@ -226,6 +227,7 @@ export default class WSClient {
action: ServerAction.WS_CLIENT_ERROR,
message: `Connection error to '${this.url}': ${error}`
});
+ }
} else {
// eslint-disable-next-line no-console
console.log(`Connection error to '${this.url}':`, error);
@@ -242,6 +244,7 @@ export default class WSClient {
break;
default: // Abnormal close
if (this.dbLogging) {
+ if (Utils.isProductionEnv()) {
// Error message
Logging.logError({
tenantID: this.logTenantID,
@@ -249,6 +252,7 @@ export default class WSClient {
action: ServerAction.WS_CLIENT_ERROR,
message: `Connection closing error to '${this.url}': ${error}`
});
+ }
} else {
// eslint-disable-next-line no-console
console.log(`Connection closing error to '${this.url}':`, error);

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1579,6 +1579,14 @@ export default class Utils {
}
}
+ public static isDevelopmentEnv(): boolean {
+ return process.env.NODE_ENV === 'development';
+ }
+
+ public static isProductionEnv(): boolean {
+ return process.env.NODE_ENV === 'production';
+ }
+
public static async checkIfUserTagIsValid(tag: Tag, req: Request): Promise<void> {
// Check that the Badge ID is not already used
if (!Authorizations.isAdmin(req.user)) {

Bypass Charging Station in error when not in prod env