Handle transaction ID = 0 + Handle properly exceptions
MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -347,8 +347,14 @@ export default class OCPPService {
if (meterValues.transactionId) {
// Get the transaction
const transaction = await TransactionStorage.getTransaction(headers.tenantID, meterValues.transactionId);
- UtilsService.assertObjectExists(ServerAction.METER_VALUES, transaction, `Transaction with ID '${meterValues.transactionId}' doesn't exist`,
- 'OCPPService', 'handleMeterValues');
+ if (!transaction) {
+ throw new BackendError({
+ source: chargingStation.id,
+ module: MODULE_NAME, method: 'handleMeterValues',
+ message: `Transaction with ID '${meterValues.transactionId}' doesn't exist`,
+ action: ServerAction.METER_VALUES,
+ });
+ }
// Save Meter Values
await OCPPStorage.saveMeterValues(headers.tenantID, newMeterValues);
// Update Transaction
@@ -425,7 +431,6 @@ export default class OCPPService {
authorize.timezone = Utils.getTimezone(chargingStation.coordinates);
// Check
const user = await Authorizations.isAuthorizedOnChargingStation(headers.tenantID, chargingStation, authorize.idTag);
-
if (user && !user.issuer) {
const tenant: Tenant = await TenantStorage.getTenant(headers.tenantID);
if (!Utils.isTenantComponentActive(tenant, TenantComponents.OCPI)) {
@@ -731,12 +736,25 @@ export default class OCPPService {
const chargingStation = await OCPPUtils.checkAndGetChargingStation(headers.chargeBoxIdentity, headers.tenantID);
// Check props
OCPPValidation.getInstance().validateStopTransaction(chargingStation, stopTransaction);
+ // Check Transaction ID = 0
+ if (stopTransaction.transactionId === 0) {
+ // Ignore it! (Cahors bug)
+ return {
+ 'status': OCPPAuthorizationStatus.ACCEPTED
+ };
+ }
// Set header
stopTransaction.chargeBoxID = chargingStation.id;
// Get the transaction
const transaction = await TransactionStorage.getTransaction(headers.tenantID, stopTransaction.transactionId);
- UtilsService.assertObjectExists(ServerAction.STOP_TRANSACTION, transaction, `Transaction with ID '${stopTransaction.transactionId}' doesn't exist`,
- 'OCPPService', 'handleStopTransaction');
+ if (!transaction) {
+ throw new BackendError({
+ source: chargingStation.id,
+ module: MODULE_NAME, method: 'handleStopTransaction',
+ message: `Transaction with ID '${stopTransaction.transactionId}' doesn't exist`,
+ action: ServerAction.STOP_TRANSACTION,
+ });
+ }
// Get the TagID that stopped the transaction
const tagId = this.getStopTransactionTagId(stopTransaction, transaction);
let user: User, alternateUser: User;

Handle transaction ID = 0 + Handle properly exceptions