X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2Focpp%2FOCPPServiceUtils.ts;h=39d738af4b19abcdbc91aa0ba45ebd89cbbba159;hb=a745e4127ed71e21b50d0397cd8ef79bf59a7573;hp=7a1fde29cc1c9af7eb4171fdbaf9ae4ad3042b6d;hpb=f126aa15c2efd27cc174011b8eb4e5bfdf27b73c;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 7a1fde29..39d738af 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -1,4 +1,28 @@ +import { DefinedError, ErrorObject } from 'ajv'; + +import { ErrorType } from '../../types/ocpp/ErrorType'; + export class OCPPServiceUtils { + protected constructor() { + // This is intentional + } + + public static ajvErrorsToErrorType(errors: ErrorObject[]): ErrorType { + for (const error of errors as DefinedError[]) { + switch (error.keyword) { + case 'type': + return ErrorType.TYPE_CONSTRAINT_VIOLATION; + case 'dependencies': + case 'required': + return ErrorType.OCCURRENCE_CONSTRAINT_VIOLATION; + case 'pattern': + case 'format': + return ErrorType.PROPERTY_CONSTRAINT_VIOLATION; + } + } + return ErrorType.FORMAT_VIOLATION; + } + protected static getLimitFromSampledValueTemplateCustomValue( value: string, limit: number,