Avoid uncatched exceptions in import users/badges and in OCPI remote start/stop session
MODIFY
src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts
src/server/ocpi/service/cpo/v2.1.1/CPOCommandsService.ts
@@ -267,6 +267,7 @@ export default class CPOCommandsService {
private static async remoteStartTransaction(action: ServerAction, tenant: Tenant, chargingStation: ChargingStation,
connector: Connector, startSession: OCPIStartSession, ocpiEndpoint: OCPIEndpoint): Promise<void> {
+ try {
const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation);
if (!chargingStationClient) {
await Logging.logError({
@@ -286,10 +287,20 @@ export default class CPOCommandsService {
} else {
await CPOCommandsService.sendCommandResponse(tenant, action, startSession.response_url, OCPICommandResponseType.REJECTED, ocpiEndpoint);
}
+ } catch (error) {
+ await Logging.logError({
+ ...LoggingHelper.getChargingStationProperties(chargingStation),
+ tenantID: tenant.id,
+ module: MODULE_NAME, method: 'remoteStartTransaction', action,
+ message: `Error while trying to Start a Transaction remotely: ${error.message as string}`,
+ detailedMessages: { startSession, chargingStation },
+ });
+ }
}
private static async remoteStopTransaction(action: ServerAction, tenant: Tenant, chargingStation: ChargingStation, transactionId: number,
stopSession: OCPIStopSession, ocpiEndpoint: OCPIEndpoint): Promise<void> {
+ try {
const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation);
if (!chargingStationClient) {
await Logging.logError({
@@ -308,6 +319,15 @@ export default class CPOCommandsService {
} else {
await CPOCommandsService.sendCommandResponse(tenant, action, stopSession.response_url, OCPICommandResponseType.REJECTED, ocpiEndpoint);
}
+ } catch (error) {
+ await Logging.logError({
+ ...LoggingHelper.getChargingStationProperties(chargingStation),
+ tenantID: tenant.id,
+ module: MODULE_NAME, method: 'remoteStopTransaction', action,
+ message: `Error while trying to Stop a Transaction remotely: ${error.message as string}`,
+ detailedMessages: { transactionId, stopSession, chargingStation },
+ });
+ }
}
private static async sendCommandResponse(tenant: Tenant, action: ServerAction, responseUrl: string, responseType: OCPICommandResponseType, ocpiEndpoint: OCPIEndpoint) {

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -453,7 +453,7 @@ export default class TagService {
await LockingManager.release(importTagsLock);
}
});
- await new Promise((resolve) => {
+ await new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
busboy.on('file', async (fileName: string, fileStream: Readable, fileInfo: FileInfo) => {
if (fileInfo.filename.slice(-4) === '.csv') {
@@ -465,7 +465,7 @@ export default class TagService {
void converter.subscribe(async (tag: ImportedTag) => {
// Check connection
if (connectionClosed) {
- throw new Error('HTTP connection has been closed');
+ reject(new Error('HTTP connection has been closed'));
}
// Check the format of the first entry
if (!result.inSuccess && !result.inError) {
@@ -477,7 +477,7 @@ export default class TagService {
res.end();
resolve();
}
- throw new Error(`Missing one of required properties: '${TagRequiredImportProperties.join(', ')}'`);
+ reject(new Error(`Missing one of required properties: '${TagRequiredImportProperties.join(', ')}'`));
}
}
// Set default value

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -454,7 +454,7 @@ export default class UserService {
await LockingManager.release(importUsersLock);
}
});
- await new Promise((resolve) => {
+ await new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
busboy.on('file', async (fileName: string, fileStream: Readable, fileInfo: FileInfo) => {
if (fileInfo.filename.slice(-4) === '.csv') {
@@ -466,7 +466,7 @@ export default class UserService {
void converter.subscribe(async (user: ImportedUser) => {
// Check connection
if (connectionClosed) {
- throw new Error('HTTP connection has been closed');
+ reject(new Error('HTTP connection has been closed'));
}
// Check the format of the first entry
if (!result.inSuccess && !result.inError) {
@@ -478,7 +478,7 @@ export default class UserService {
res.end();
resolve();
}
- throw new Error(`Missing one of required properties: '${UserRequiredImportProperties.join(', ')}'`);
+ reject(new Error(`Missing one of required properties: '${UserRequiredImportProperties.join(', ')}'`));
}
}
// Set default value

Avoid uncatched exceptions in import users/badges and in OCPI remote start/stop session