X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fui-websocket-services%2FAbstractUIService.ts;h=0bc34bd99772f6e2f5cde37d397717af5d69668e;hb=794aea9d3e6b713d55bf5adb06faa211206cfa77;hp=b4905da4292975a91d1baeb8f4e6d1c2069b23e2;hpb=bc464bb1fb95c50a14b25478d35be76b7d8e5498;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-websocket-services/AbstractUIService.ts b/src/charging-station/ui-websocket-services/AbstractUIService.ts index b4905da4..0bc34bd9 100644 --- a/src/charging-station/ui-websocket-services/AbstractUIService.ts +++ b/src/charging-station/ui-websocket-services/AbstractUIService.ts @@ -3,7 +3,7 @@ import { ProtocolCommand, ProtocolRequestHandler } from '../../types/UIProtocol' import BaseError from '../../exception/BaseError'; import { JsonType } from '../../types/JsonType'; import UIWebSocketServer from '../UIWebSocketServer'; -import getLogger from '../../utils/Logger'; +import logger from '../../utils/Logger'; export default abstract class AbstractUIService { protected readonly uiWebSocketServer: UIWebSocketServer; @@ -21,24 +21,27 @@ export default abstract class AbstractUIService { if (this.messageHandlers.has(command)) { try { // Call the method to build the message response - messageResponse = await this.messageHandlers.get(command)(payload) as JsonType; + messageResponse = (await this.messageHandlers.get(command)(payload)) as JsonType; } catch (error) { // Log - getLogger().error(this.uiWebSocketServer.logPrefix() + ' Handle message error: %j', error); + logger.error(this.uiWebSocketServer.logPrefix() + ' Handle message error: %j', error); throw error; } } else { // Throw exception - throw new BaseError(`${command} is not implemented to handle message payload ${JSON.stringify(payload, null, 2)}`); + throw new BaseError( + `${command} is not implemented to handle message payload ${JSON.stringify( + payload, + null, + 2 + )}` + ); } // Send the built message response this.uiWebSocketServer.broadcastToClients(this.buildProtocolMessage(command, messageResponse)); } - protected buildProtocolMessage( - command: ProtocolCommand, - payload: JsonType, - ): string { + protected buildProtocolMessage(command: ProtocolCommand, payload: JsonType): string { return JSON.stringify([command, payload]); }