Better handle check sessions/cdrs
MODIFY
src/client/ocpi/CpoOCPIClient.ts
src/client/ocpi/CpoOCPIClient.ts
@@ -874,7 +874,7 @@ export default class CpoOCPIClient extends OCPIClient {
},
});
return false;
- }
+ } else if (OCPIUtilsService.isSuccessResponse(response.data)) {
const cdr = response.data.data as OCPICdr;
if (cdr) {
transaction.ocpiData.cdrCheckedOn = new Date();
@@ -889,13 +889,16 @@ export default class CpoOCPIClient extends OCPIClient {
});
return true;
}
- throw new BackendError({
+ }
+ await Logging.logError({
+ tenantID: this.tenant.id,
source: transaction.chargeBoxID,
action: ServerAction.OCPI_CHECK_CDRS,
message: `Failed to check CDR of OCPI Session ID '${transaction.ocpiData.session.id}' (ID '${transaction.id}') at ${cdrsUrl}/${transaction.ocpiData.cdr.id}`,
module: MODULE_NAME, method: 'checkCdr',
- detailedMessages: { cdr: transaction.ocpiData.cdr, data: response.data }
+ detailedMessages: { response: response.data, cdr: transaction.ocpiData.cdr }
});
+ return false;
}
private async checkSession(transaction: Transaction): Promise<boolean> {
@@ -924,27 +927,31 @@ export default class CpoOCPIClient extends OCPIClient {
'Authorization': `Token ${this.ocpiEndpoint.token}`
},
});
+ if (OCPIUtilsService.isSuccessResponse(response.data)) {
+ const session = response.data.data as OCPISession;
+ if (session) {
await Logging.logInfo({
tenantID: this.tenant.id,
source: transaction.chargeBoxID,
action: ServerAction.OCPI_CHECK_SESSIONS,
message: `OCPI Session ID '${transaction.ocpiData.session.id}' (ID '${transaction.id}') checked successfully`,
module: MODULE_NAME, method: 'checkSession',
- detailedMessages: { transaction, response: response.data }
+ detailedMessages: { response: response.data, transaction }
});
- const session = response.data.data as OCPISession;
- if (session) {
transaction.ocpiData.sessionCheckedOn = new Date();
await TransactionStorage.saveTransaction(this.tenant.id, transaction);
return true;
}
- throw new BackendError({
+ }
+ await Logging.logError({
+ tenantID: this.tenant.id,
source: transaction.chargeBoxID,
action: ServerAction.OCPI_CHECK_SESSIONS,
message: `Failed to check OCPI Session ID '${transaction.ocpiData.session.id}' (ID '${transaction.id}') at ${sessionsUrl}`,
module: MODULE_NAME, method: 'checkSession',
- detailedMessages: { data: response.data }
+ detailedMessages: { response: response.data, transaction }
});
+ return false;
}
private async checkLocation(location: OCPILocation): Promise<boolean> {

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
@@ -24,6 +24,7 @@ import Logging from '../../../../utils/Logging';
import { OCPICdr } from '../../../../types/ocpi/OCPICdr';
import OCPICredential from '../../../../types/ocpi/OCPICredential';
import OCPIEndpoint from '../../../../types/ocpi/OCPIEndpoint';
+import { OCPIResponse } from '../../../../types/ocpi/OCPIResponse';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
import { OCPIStatusCode } from '../../../../types/ocpi/OCPIStatusCode';
import OCPIUtils from '../../OCPIUtils';
@@ -47,6 +48,11 @@ import moment from 'moment';
const MODULE_NAME = 'OCPIUtilsService';
export default class OCPIUtilsService {
+ public static isSuccessResponse(response: OCPIResponse): boolean {
+ return !Utils.objectHasProperty(response, 'status_code') ||
+ response.status_code === 1000;
+ }
+
public static convertEvseToChargingStation(evse: Partial<OCPIEvse>, location: OCPILocation): ChargingStation {
const chargingStation = {
maximumPower: 0,

Better handle check sessions/cdrs