Type alias for OCPP stack response and error handling
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 26 Nov 2022 21:19:21 +0000 (22:19 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 26 Nov 2022 21:19:21 +0000 (22:19 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/types/ocpp/Requests.ts

index 1699f046da3982353a45ec637d43adce4b91d6d8..04c33a1028c90e0f7ba0f833e717c60af6ec6cd3 100644 (file)
@@ -42,11 +42,13 @@ import {
   AvailabilityType,
   BootNotificationRequest,
   CachedRequest,
+  ErrorCallback,
   HeartbeatRequest,
   IncomingRequest,
   IncomingRequestCommand,
   MeterValuesRequest,
   RequestCommand,
+  ResponseCallback,
   StatusNotificationRequest,
 } from '../types/ocpp/Requests';
 import {
@@ -1412,8 +1414,8 @@ export default class ChargingStation {
     let errorType: ErrorType;
     let errorMessage: string;
     let errorDetails: JsonType;
-    let responseCallback: (payload: JsonType, requestPayload: JsonType) => void;
-    let errorCallback: (error: OCPPError, requestStatistic?: boolean) => void;
+    let responseCallback: ResponseCallback;
+    let errorCallback: ErrorCallback;
     let requestCommandName: RequestCommand | IncomingRequestCommand;
     let requestPayload: JsonType;
     let cachedRequest: CachedRequest;
index bdfffc3725973ab6b5521889cce9f9b245e8bc24..6c241042e8f69b7ebbe836a6a54921acb4bfb06c 100644 (file)
@@ -10,10 +10,12 @@ import type { JsonObject, JsonType } from '../../types/JsonType';
 import { ErrorType } from '../../types/ocpp/ErrorType';
 import { MessageType } from '../../types/ocpp/MessageType';
 import {
+  ErrorCallback,
   IncomingRequestCommand,
   OutgoingRequest,
   RequestCommand,
   RequestParams,
+  ResponseCallback,
   ResponseType,
 } from '../../types/ocpp/Requests';
 import type { ErrorResponse, Response } from '../../types/ocpp/Responses';
@@ -308,8 +310,8 @@ export default abstract class OCPPRequestService {
     messagePayload: JsonType | OCPPError,
     messageType: MessageType,
     commandName?: RequestCommand | IncomingRequestCommand,
-    responseCallback?: (payload: JsonType, requestPayload: JsonType) => void,
-    errorCallback?: (error: OCPPError, requestStatistic?: boolean) => void
+    responseCallback?: ResponseCallback,
+    errorCallback?: ErrorCallback
   ): string {
     let messageToSend: string;
     // Type of message
index aeedae02f3a3325c777ccfc7e8a05b6668ebce4d..1aa015b6c956500e953a0d3bc23caa590f244dbe 100644 (file)
@@ -36,9 +36,13 @@ export const IncomingRequestCommand = {
 
 export type IncomingRequest = [MessageType.CALL_MESSAGE, string, IncomingRequestCommand, JsonType];
 
+export type ResponseCallback = (payload: JsonType, requestPayload: JsonType) => void;
+
+export type ErrorCallback = (error: OCPPError, requestStatistic?: boolean) => void;
+
 export type CachedRequest = [
-  (payload: JsonType, requestPayload: JsonType) => void,
-  (error: OCPPError, requestStatistic?: boolean) => void,
+  ResponseCallback,
+  ErrorCallback,
   RequestCommand | IncomingRequestCommand,
   JsonType
 ];