}
async onMessage(messageEvent: MessageEvent): Promise<void> {
- let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, '', ''];
- let responseCallback: (payload?, requestPayload?) => void;
+ let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, {}, {}];
+ let responseCallback: (payload?: Record<string, unknown> | string, requestPayload?: Record<string, unknown>) => void;
let rejectCallback: (error: OCPPError) => void;
let requestPayload: Record<string, unknown>;
let errMsg: string;
throw new Error(`Error request for message id ${messageId} is not iterable`);
}
delete this._requests[messageId];
- rejectCallback(new OCPPError(commandName, commandPayload, errorDetails));
+ rejectCallback(new OCPPError(commandName, commandPayload.toString(), errorDetails));
break;
// Error
default:
}
}
- async sendError(messageId: string, err: Error | OCPPError, commandName: RequestCommand | IncomingRequestCommand): Promise<unknown> {
- // Check exception type: only OCPP error are accepted
- const error = err instanceof OCPPError ? err : new OCPPError(ErrorType.INTERNAL_ERROR, err.message, err.stack && err.stack);
+ async sendError(messageId: string, error: OCPPError, commandName: RequestCommand | IncomingRequestCommand): Promise<unknown> {
// Send error
return this.sendMessage(messageId, error, MessageType.CALL_ERROR_MESSAGE, commandName);
}
- async sendMessage(messageId: string, commandParams, messageType: MessageType = MessageType.CALL_RESULT_MESSAGE, commandName: RequestCommand | IncomingRequestCommand): Promise<any> {
+ async sendMessage(messageId: string, commandParams: any, messageType: MessageType = MessageType.CALL_RESULT_MESSAGE, commandName: RequestCommand | IncomingRequestCommand): Promise<any> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
const self = this;
// Send a message through wsConnection
}
// Yes: Send Message
this._wsConnection.send(messageToSend);
- } else {
+ } else if (commandName !== RequestCommand.BOOT_NOTIFICATION) {
let dups = false;
// Handle dups in buffer
for (const message of this._messageQueue) {
}
// Function that will receive the request's response
- async function responseCallback(payload, requestPayload): Promise<void> {
+ async function responseCallback(payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>): Promise<void> {
if (self.getEnableStatistics()) {
self._statistics.addMessage(commandName, messageType);
}
});
}
- async handleResponse(commandName: RequestCommand, payload, requestPayload): Promise<void> {
+ async handleResponse(commandName: RequestCommand, payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>): Promise<void> {
const responseCallbackFn = 'handleResponse' + commandName;
if (typeof this[responseCallbackFn] === 'function') {
await this[responseCallbackFn](payload, requestPayload);
logger.debug(this._logPrefix() + ' Heartbeat response received: %j to Heartbeat request: %j', payload, requestPayload);
}
- async handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload): Promise<void> {
+ async handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload: Record<string, unknown>): Promise<void> {
let response;
// Call
if (typeof this['handleRequest' + commandName] === 'function') {