Let the exception throw outside the billing
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -405,7 +405,6 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
}
public async startTransaction(transaction: Transaction): Promise<BillingDataTransactionStart> {
- try {
// Check Stripe
await this.checkConnection();
// Check Transaction
@@ -435,24 +434,12 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
action: ServerAction.BILLING_TRANSACTION
});
}
- } catch (error) {
- Logging.logError({
- tenantID: this.tenantID,
- user: transaction.userID,
- source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_TRANSACTION,
- module: MODULE_NAME, method: 'startTransaction',
- message: `Billing error in Start Transaction: ${error.message}`,
- detailedMessages: { error: error.message, stack: error.stack }
- });
- }
return {
cancelTransaction: false
};
}
public async updateTransaction(transaction: Transaction): Promise<BillingDataTransactionUpdate> {
- try {
// Check User
if (!transaction.userID || !transaction.user) {
throw new BackendError({
@@ -463,24 +450,12 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
action: ServerAction.BILLING_TRANSACTION
});
}
- } catch (error) {
- Logging.logError({
- tenantID: this.tenantID,
- user: transaction.userID,
- source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_TRANSACTION,
- module: MODULE_NAME, method: 'updateTransaction',
- message: `Billing error in Update Transaction: ${error.message}`,
- detailedMessages: { error: error.message, stack: error.stack }
- });
- }
return {
cancelTransaction: false
};
}
public async stopTransaction(transaction: Transaction): Promise<BillingDataTransactionStop> {
- try {
// Check Stripe
await this.checkConnection();
// Check object
@@ -548,22 +523,6 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
invoiceStatus: invoice.invoice.status,
invoiceItem: invoice.invoiceItem,
};
- } catch (error) {
- Logging.logError({
- tenantID: this.tenantID,
- user: transaction.userID,
- source: Constants.CENTRAL_SERVER,
- action: ServerAction.BILLING_TRANSACTION,
- module: MODULE_NAME, method: 'stopTransaction',
- message: `Billing error in Stop Transaction: ${error.message}`,
- detailedMessages: { error: error.message, stack: error.stack }
- });
- return {
- status: BillingStatus.UNBILLED,
- invoiceStatus: null,
- invoiceItem: null
- };
- }
}
public async checkIfUserCanBeCreated(user: User): Promise<boolean> {

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
@@ -109,19 +109,43 @@ export default class OCPPUtils {
switch (action) {
// Start Transaction
case TransactionAction.START:
+ try {
// Delegate
await billingImpl.startTransaction(transaction);
// Update
transaction.billingData = {
lastUpdate: new Date()
};
+ } catch (error) {
+ Logging.logError({
+ tenantID: tenantID,
+ user: transaction.userID,
+ source: Constants.CENTRAL_SERVER,
+ action: ServerAction.BILLING_TRANSACTION,
+ module: MODULE_NAME, method: 'billTransaction',
+ message: `Failed to bill transaction ${transaction.id}`,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ }
break;
// Meter Values
case TransactionAction.UPDATE:
+ try {
// Delegate
await billingImpl.updateTransaction(transaction);
// Update
transaction.billingData.lastUpdate = new Date();
+ } catch (error) {
+ Logging.logError({
+ tenantID: tenantID,
+ user: transaction.userID,
+ source: Constants.CENTRAL_SERVER,
+ action: ServerAction.BILLING_TRANSACTION,
+ module: MODULE_NAME, method: 'billTransaction',
+ message: `Failed to bill transaction ${transaction.id}`,
+ detailedMessages: { error: error.message, stack: error.stack }
+ });
+ }
break;
// Stop Transaction
case TransactionAction.STOP:

MODIFY
src/server/rest/service/BillingService.ts
src/server/rest/service/BillingService.ts
@@ -463,7 +463,6 @@ export default class BillingService {
Utils.convertToInt(filteredRequest.transactionID));
UtilsService.assertObjectExists(action, transaction, `Transaction '${filteredRequest.transactionID}' does not exist`,
MODULE_NAME, 'handleCreateTransactionInvoice', req.user);
- try {
// Create an invoice for the transaction
const billingDataStop = await billingImpl.stopTransaction(transaction);
// Update transaction
@@ -483,17 +482,6 @@ export default class BillingService {
message: `Transaction ID '${transaction.id}' has been billed successfully`,
action: action,
});
- } catch (error) {
- throw new AppError({
- source: Constants.CENTRAL_SERVER,
- module: MODULE_NAME,
- errorCode: HTTPError.GENERAL_ERROR,
- user: req.user, actionOnUser: transaction.userID,
- method: 'handleCreateTransactionInvoice',
- message: `Failed to link transaction ${transaction.id} to invoice`,
- detailedMessages: { error: error.message, stack: error.stack }
- });
- }
// Ok
res.json(Object.assign(Constants.REST_RESPONSE_SUCCESS));
next();

Let the exception throw outside the billing