refactor: improve OCPP error defaults and usage
[e-mobility-charging-stations-simulator.git] / src / exception / OCPPError.ts
1 // Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
2
3 import { BaseError } from './BaseError';
4 import {
5 ErrorType,
6 type IncomingRequestCommand,
7 type JsonType,
8 type RequestCommand,
9 } from '../types';
10 import { Constants } from '../utils';
11
12 export class OCPPError extends BaseError {
13 code: ErrorType;
14 command?: RequestCommand | IncomingRequestCommand;
15 details?: JsonType;
16
17 constructor(
18 code: ErrorType,
19 message: string,
20 command?: RequestCommand | IncomingRequestCommand,
21 details?: JsonType,
22 ) {
23 super(message);
24
25 this.code = code;
26 this.command =
27 command ?? (Constants.UNKNOWN_COMMAND as RequestCommand | IncomingRequestCommand);
28 this.details = details;
29 }
30 }