Cleanup files and files name.
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPError.ts
1 // Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
2
3 import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests';
4
5 import { ErrorType } from '../../types/ocpp/ErrorType';
6
7 export default class OCPPError extends Error {
8 code: ErrorType | IncomingRequestCommand;
9 command?: RequestCommand | IncomingRequestCommand;
10 details?: Record<string, unknown>;
11
12 constructor(code: ErrorType | IncomingRequestCommand, message: string, command?: RequestCommand | IncomingRequestCommand, details?: Record<string, unknown>) {
13 super(message);
14
15 this.name = new.target.name;
16 this.code = code ?? ErrorType.GENERIC_ERROR;
17 this.message = message ?? '';
18 this.command = command;
19 this.details = details ?? {};
20
21 Object.setPrototypeOf(this, new.target.prototype);
22
23 Error.captureStackTrace ? Error.captureStackTrace(this, this.constructor) : (this.stack = (new Error()).stack);
24 }
25 }