refactor: organize constants
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPRequestService.ts
index 3eb85e3089a232f21b50b5082e644dceec573505..06258fe4a1e071f7f1581420116329a80906dcd7 100644 (file)
@@ -1,16 +1,16 @@
 import Ajv, { type JSONSchemaType } from 'ajv';
 import ajvFormats from 'ajv-formats';
 
-import { OCPPConstants, type OCPPResponseService, OCPPServiceUtils } from './internal';
+import { OCPPConstants } from './OCPPConstants';
+import type { OCPPResponseService } from './OCPPResponseService';
+import { OCPPServiceUtils } from './OCPPServiceUtils';
 import type { ChargingStation } from '../../charging-station';
 import { OCPPError } from '../../exception';
 import { PerformanceStatistics } from '../../performance';
 import {
-  type EmptyObject,
   type ErrorCallback,
   type ErrorResponse,
   ErrorType,
-  type HandleErrorParams,
   type IncomingRequestCommand,
   type JsonObject,
   type JsonType,
@@ -23,7 +23,7 @@ import {
   type ResponseCallback,
   type ResponseType,
 } from '../../types';
-import { Constants, Utils, logger } from '../../utils';
+import { Constants, ErrorUtils, Utils, logger } from '../../utils';
 
 const moduleName = 'OCPPRequestService';
 
@@ -127,7 +127,7 @@ export abstract class OCPPRequestService {
         commandName
       );
     } catch (error) {
-      this.handleSendMessageError(chargingStation, commandName, error as Error, {
+      ErrorUtils.handleSendMessageError(chargingStation, commandName, error as Error, {
         throwError: true,
       });
     }
@@ -149,7 +149,7 @@ export abstract class OCPPRequestService {
         commandName
       );
     } catch (error) {
-      this.handleSendMessageError(chargingStation, commandName, error as Error);
+      ErrorUtils.handleSendMessageError(chargingStation, commandName, error as Error);
     }
   }
 
@@ -174,7 +174,7 @@ export abstract class OCPPRequestService {
         params
       );
     } catch (error) {
-      this.handleSendMessageError(chargingStation, commandName, error as Error, {
+      ErrorUtils.handleSendMessageError(chargingStation, commandName, error as Error, {
         throwError: params.throwError,
       });
     }
@@ -475,18 +475,6 @@ export abstract class OCPPRequestService {
     return messageToSend;
   }
 
-  private handleSendMessageError(
-    chargingStation: ChargingStation,
-    commandName: RequestCommand | IncomingRequestCommand,
-    error: Error,
-    params: HandleErrorParams<EmptyObject> = { throwError: false }
-  ): void {
-    logger.error(`${chargingStation.logPrefix()} Request command '${commandName}' error:`, error);
-    if (params?.throwError === true) {
-      throw error;
-    }
-  }
-
   // eslint-disable-next-line @typescript-eslint/no-unused-vars
   public abstract requestHandler<ReqType extends JsonType, ResType extends JsonType>(
     chargingStation: ChargingStation,