-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocpp-call-error.ts
46 lines (40 loc) · 1.32 KB
/
ocpp-call-error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { type RpcCallErrorV16 } from "./../types/v16";
import { OCPPMessageType, type OCPPErrorCodeType } from "./common";
import { randomUUID } from "crypto";
import { type RpcCallErrorV201 } from "./../types/v201";
import { type OCPPErrorCodeV16, type OCPPErrorCodeV201 } from "./../types";
export class OCPPCallError<T extends OCPPErrorCodeType> {
public messageTypeId: OCPPMessageType.CALL_ERROR;
public messageId: string;
public errorCode: T;
public errorDescription: string;
public errorDetails: Record<string, unknown>;
public toRPCObject (): RpcCallErrorV16 | RpcCallErrorV201 {
return [
OCPPMessageType.CALL_ERROR,
this.messageId,
this.errorCode,
this.errorDescription,
this.errorDetails
];
}
public constructor ({
messageId,
errorCode,
errorDescription,
errorDetails
}: {
messageId?: string
errorCode: T
errorDescription: string
errorDetails?: Record<string, unknown>
}) {
this.messageTypeId = OCPPMessageType.CALL_ERROR;
this.messageId = messageId ?? randomUUID();
this.errorCode = errorCode;
this.errorDescription = errorDescription;
this.errorDetails = errorDetails ?? {};
}
}
export class OCPPCallErrorV16 extends OCPPCallError<OCPPErrorCodeV16> {}
export class OCPPCallErrorV201 extends OCPPCallError<OCPPErrorCodeV201> {}