From edcec46a323c66fbb8fb73ab0c3b83077c84a39c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 14 Aug 2025 13:12:14 +0200 Subject: [PATCH] refactor: align error handling helpers behavior MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 7 +++---- src/utils/ErrorUtils.ts | 2 +- tests/utils/ErrorUtils.test.ts | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 2d64527d..7c0afb28 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -694,7 +694,6 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { error as Error, { errorResponse: OCPP16Constants.OCPP_CANCEL_RESERVATION_RESPONSE_REJECTED, - throwError: false, } )! } @@ -914,7 +913,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { chargingStation, OCPP16IncomingRequestCommand.DATA_TRANSFER, error as Error, - { errorResponse: OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED, throwError: false } + { errorResponse: OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED } )! } } @@ -1180,7 +1179,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { chargingStation, OCPP16IncomingRequestCommand.GET_DIAGNOSTICS, error as Error, - { errorResponse: OCPP16Constants.OCPP_RESPONSE_EMPTY, throwError: false } + { errorResponse: OCPP16Constants.OCPP_RESPONSE_EMPTY } )! } } else { @@ -1374,7 +1373,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { chargingStation, OCPP16IncomingRequestCommand.RESERVE_NOW, error as Error, - { errorResponse: OCPP16Constants.OCPP_RESERVATION_RESPONSE_FAULTED, throwError: false } + { errorResponse: OCPP16Constants.OCPP_RESERVATION_RESPONSE_FAULTED } )! } } diff --git a/src/utils/ErrorUtils.ts b/src/utils/ErrorUtils.ts index 75998b96..5f4082c3 100644 --- a/src/utils/ErrorUtils.ts +++ b/src/utils/ErrorUtils.ts @@ -131,7 +131,7 @@ export const handleIncomingRequestError = ( params = { ...{ consoleOut: false, - throwError: true, + throwError: false, }, ...params, } diff --git a/tests/utils/ErrorUtils.test.ts b/tests/utils/ErrorUtils.test.ts index 9da6f63d..77ebcc09 100644 --- a/tests/utils/ErrorUtils.test.ts +++ b/tests/utils/ErrorUtils.test.ts @@ -87,19 +87,18 @@ await describe('ErrorUtils test suite', async () => { const error = new Error() expect(() => { handleIncomingRequestError(chargingStation, IncomingRequestCommand.CLEAR_CACHE, error) - }).toThrow(error) + }).not.toThrow(error) expect(() => { handleIncomingRequestError(chargingStation, IncomingRequestCommand.CLEAR_CACHE, error, { - throwError: false, + throwError: true, }) - }).not.toThrow() + }).toThrow() const errorResponse = { status: GenericStatus.Rejected, } expect( handleIncomingRequestError(chargingStation, IncomingRequestCommand.CLEAR_CACHE, error, { errorResponse, - throwError: false, }) ).toStrictEqual(errorResponse) expect(chargingStation.logPrefix.mock.calls.length).toBe(3) -- 2.43.0