Cleanup files and files name.
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPError.ts
CommitLineData
b4d34251
JB
1// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
2
a6b3c6c3
JB
3import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests';
4
14763b46 5import { ErrorType } from '../../types/ocpp/ErrorType';
14763b46
JB
6
7export default class OCPPError extends Error {
8 code: ErrorType | IncomingRequestCommand;
a6b3c6c3 9 command?: RequestCommand | IncomingRequestCommand;
ae8ee665 10 details?: Record<string, unknown>;
14763b46 11
ae8ee665 12 constructor(code: ErrorType | IncomingRequestCommand, message: string, command?: RequestCommand | IncomingRequestCommand, details?: Record<string, unknown>) {
14763b46
JB
13 super(message);
14
15 this.name = new.target.name;
16 this.code = code ?? ErrorType.GENERIC_ERROR;
17 this.message = message ?? '';
9292e32a 18 this.command = command;
14763b46
JB
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}