X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPServiceUtils.ts;h=96b34218bae93f78a595545a29b2969fc91000fc;hb=60ddad538d0a01ece43f4f70928a9decf3531dda;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..96b34218 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -1,4 +1,28 @@ +import type { 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,