Fix error handling of incoming OCPP request
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 13 Aug 2021 21:03:40 +0000 (23:03 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 13 Aug 2021 21:03:40 +0000 (23:03 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ocpp/1.6/OCCP16IncomingRequestService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts

index 40f80a2c50e398edb36adcb8b242f4d0b136ac80..4dc5ed6630b39825bdcca890c5c0e76acab2b7e9 100644 (file)
@@ -385,11 +385,10 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         throw new Error(`Diagnostics transfer failed with error code ${accessResponse.code.toString()}${uploadResponse?.code && '|' + uploadResponse?.code.toString()}`);
       } catch (error) {
         await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification(OCPP16DiagnosticsStatus.UploadFailed);
-        this.handleIncomingRequestError(IncomingRequestCommand.GET_DIAGNOSTICS, error);
         if (ftpClient) {
           ftpClient.close();
         }
-        return Constants.OCPP_RESPONSE_EMPTY;
+        return this.handleIncomingRequestError(IncomingRequestCommand.GET_DIAGNOSTICS, error, Constants.OCPP_RESPONSE_EMPTY);
       }
     } else {
       logger.error(`${this.chargingStation.logPrefix()} Unsupported protocol ${uri.protocol} to transfer the diagnostic logs archive`);
index 9980e5d89ec7a8406ec82aae4ddf261820be5bf5..ff2dfd4c18d4f4098d1374cdb45767a48dd27c55 100644 (file)
@@ -9,8 +9,11 @@ export default abstract class OCPPIncomingRequestService {
     this.chargingStation = chargingStation;
   }
 
-  public handleIncomingRequestError(commandName: IncomingRequestCommand, error: Error): void {
+  public handleIncomingRequestError(commandName: IncomingRequestCommand, error: Error, ocppResponse?): unknown {
     logger.error(this.chargingStation.logPrefix() + ' Incoming request command ' + commandName + ' error: %j', error);
+    if (ocppResponse) {
+      return ocppResponse;
+    }
     throw error;
   }