Display WS protocol not provided in cumtomer's tenant
MODIFY
src/server/ocpp/json/JsonWSConnection.ts
src/server/ocpp/json/JsonWSConnection.ts
@@ -31,6 +31,7 @@ export default class JsonWSConnection extends WSConnection {
constructor(wsConnection: WebSocket, req: http.IncomingMessage, wsServer: JsonCentralSystemServer) {
// Call super
super(wsConnection, req, wsServer);
+ let backendError: BackendError;
// Check Protocol (required field of OCPP spec)
switch (wsConnection.protocol) {
// OCPP 1.6?
@@ -42,13 +43,22 @@ export default class JsonWSConnection extends WSConnection {
break;
// Not Found
default:
- // Error
- throw new BackendError({
+ backendError = new BackendError({
source: this.getChargingStationID(),
module: MODULE_NAME,
method: 'constructor',
- message: `Protocol ${wsConnection.protocol} not supported`
+ message: wsConnection.protocol ?
+ `Web Socket Protocol '${wsConnection.protocol}' not supported` : 'Web Socket Protocol is mandatory'
});
+ // Log in the right Tenants
+ void Logging.logException(
+ backendError,
+ ServerAction.WS_JSON_CONNECTION_ERROR,
+ this.getChargingStationID(),
+ MODULE_NAME, 'constructor',
+ this.getTenantID()
+ );
+ throw backendError;
}
this.isConnectionAlive = true;
// Handle Socket ping

MODIFY
src/server/ocpp/json/WSConnection.ts
src/server/ocpp/json/WSConnection.ts
@@ -28,7 +28,6 @@ export default abstract class WSConnection {
private clientIP: string | string[];
private wsConnection: WebSocket;
private requests: { [id: string]: OCPPRequest };
- private validTenant: boolean;
constructor(wsConnection: WebSocket, req: http.IncomingMessage, wsServer: JsonCentralSystemServer) {
// Init
@@ -44,7 +43,6 @@ export default abstract class WSConnection {
message: `WS connection opening attempts with URL: '${req.url}'`,
});
// Default
- this.validTenant = false;
this.requests = {};
// Check URL: remove starting and trailing '/'
if (this.url.endsWith('/')) {
@@ -120,7 +118,6 @@ export default abstract class WSConnection {
try {
// Check Tenant?
this.tenant = await DatabaseUtils.checkTenant(this.tenantID);
- this.validTenant = true;
} catch (error) {
// Custom Error
await Logging.logException(error, ServerAction.WS_CONNECTION, this.getChargingStationID(), 'WSConnection', 'initialize', this.tenantID);
@@ -328,12 +325,8 @@ export default abstract class WSConnection {
}
public getTenantID(): string {
- if (this.isTenantValid()) {
return this.tenantID;
}
- // No: go to the master tenant
- return Constants.DEFAULT_TENANT;
- }
public getTenant(): Tenant {
return this.tenant;
@@ -347,10 +340,6 @@ export default abstract class WSConnection {
return `${this.getTenantID()}~${this.getChargingStationID()}`;
}
- public isTenantValid(): boolean {
- return this.validTenant;
- }
-
public isWSConnectionOpen(): boolean {
return this.getConnectionStatus() === OPEN;
}

Display WS protocol not provided in cumtomer's tenant