let errorMessage: string;
let errorDetails: JsonType;
let responseCallback: (payload: JsonType, requestPayload: JsonType) => void;
- let rejectCallback: (error: OCPPError, requestStatistic?: boolean) => void;
+ let errorCallback: (error: OCPPError, requestStatistic?: boolean) => void;
let requestCommandName: RequestCommand | IncomingRequestCommand;
let requestPayload: JsonType;
let cachedRequest: CachedRequest;
// Outcome Message
case MessageType.CALL_RESULT_MESSAGE:
[, , commandPayload] = request as Response;
+ if (!this.requests.has(messageId)) {
+ // Error
+ throw new OCPPError(
+ ErrorType.INTERNAL_ERROR,
+ `Response for unknown message id ${messageId}`,
+ null,
+ commandPayload
+ );
+ }
// Respond
cachedRequest = this.requests.get(messageId);
if (Utils.isIterable(cachedRequest)) {
requestCommandName ?? ''
}' received response payload: ${JSON.stringify(request)}`
);
- if (!responseCallback) {
+ responseCallback(commandPayload, requestPayload);
+ break;
+ // Error Message
+ case MessageType.CALL_ERROR_MESSAGE:
+ [, , errorType, errorMessage, errorDetails] = request as ErrorResponse;
+ if (!this.requests.has(messageId)) {
// Error
throw new OCPPError(
ErrorType.INTERNAL_ERROR,
- `Response for unknown message id ${messageId}`,
+ `Error response for unknown message id ${messageId}`,
null,
- commandPayload
+ { errorType, errorMessage, errorDetails }
);
}
- responseCallback(commandPayload, requestPayload);
- break;
- // Error Message
- case MessageType.CALL_ERROR_MESSAGE:
- [, , errorType, errorMessage, errorDetails] = request as ErrorResponse;
cachedRequest = this.requests.get(messageId);
if (Utils.isIterable(cachedRequest)) {
- [, rejectCallback, requestCommandName] = cachedRequest;
+ [, errorCallback, requestCommandName] = cachedRequest;
} else {
throw new OCPPError(
ErrorType.PROTOCOL_ERROR,
requestCommandName ?? ''
}' received error payload: ${JSON.stringify(request)}`
);
- if (!rejectCallback) {
- // Error
- throw new OCPPError(
- ErrorType.INTERNAL_ERROR,
- `Error response for unknown message id ${messageId}`,
- null,
- { errorType, errorMessage, errorDetails }
- );
- }
- rejectCallback(
- new OCPPError(errorType, errorMessage, requestCommandName, errorDetails)
- );
+ errorCallback(new OCPPError(errorType, errorMessage, requestCommandName, errorDetails));
break;
// Error
default:
(await this.ocppRequestService.sendError(
messageId,
error as OCPPError,
- Utils.isString(commandName) ? commandName : requestCommandName ?? null
+ commandName ?? requestCommandName ?? null
));
}
}
messageType,
commandName,
responseCallback,
- rejectCallback
+ errorCallback
);
if (this.chargingStation.getEnableStatistics()) {
this.chargingStation.performanceStatistics.addRequestStatistic(
// Reject it but keep the request in the cache
return reject(ocppError);
}
- return rejectCallback(ocppError, false);
+ return errorCallback(ocppError, false);
} else {
// Reject it
- return rejectCallback(
+ return errorCallback(
new OCPPError(
ErrorType.GENERIC_ERROR,
`WebSocket closed for non buffered message id '${messageId}' with content '${messageToSend}'`,
* @param error
* @param requestStatistic
*/
- function rejectCallback(error: OCPPError, requestStatistic = true): void {
+ function errorCallback(error: OCPPError, requestStatistic = true): void {
if (requestStatistic && self.chargingStation.getEnableStatistics()) {
self.chargingStation.performanceStatistics.addRequestStatistic(
commandName,
messageType: MessageType,
commandName?: RequestCommand | IncomingRequestCommand,
responseCallback?: (payload: JsonType, requestPayload: JsonType) => Promise<void>,
- rejectCallback?: (error: OCPPError, requestStatistic?: boolean) => void
+ errorCallback?: (error: OCPPError, requestStatistic?: boolean) => void
): string {
let messageToSend: string;
// Type of message
// Build request
this.chargingStation.requests.set(messageId, [
responseCallback,
- rejectCallback,
+ errorCallback,
commandName,
messagePayload as JsonType,
]);