Improve OCPP error handling, fix performance storage default file path
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / OCPPError.ts
CommitLineData
a6b3c6c3
JB
1import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests';
2
14763b46 3import { ErrorType } from '../../types/ocpp/ErrorType';
14763b46
JB
4
5export default class OCPPError extends Error {
6 code: ErrorType | IncomingRequestCommand;
a6b3c6c3 7 command?: RequestCommand | IncomingRequestCommand;
14763b46
JB
8 details?: unknown;
9
a6b3c6c3 10 constructor(code: ErrorType | IncomingRequestCommand, message: string, command?: RequestCommand | IncomingRequestCommand, details?: unknown) {
14763b46
JB
11 super(message);
12
13 this.name = new.target.name;
14 this.code = code ?? ErrorType.GENERIC_ERROR;
15 this.message = message ?? '';
a6b3c6c3 16 this.message = command ?? '';
14763b46
JB
17 this.details = details ?? {};
18
19 Object.setPrototypeOf(this, new.target.prototype);
20
21 Error.captureStackTrace ? Error.captureStackTrace(this, this.constructor) : (this.stack = (new Error()).stack);
22 }
23}