1 // Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
3 import { IncomingRequestCommand
, RequestCommand
} from
'../../types/ocpp/Requests';
5 import { ErrorType
} from
'../../types/ocpp/ErrorType';
7 export default class OCPPError
extends Error {
8 code
: ErrorType
| IncomingRequestCommand
;
9 command
?: RequestCommand
| IncomingRequestCommand
;
10 details
?: Record
<string, unknown
>;
12 constructor(code
: ErrorType
| IncomingRequestCommand
, message
: string, command
?: RequestCommand
| IncomingRequestCommand
, details
?: Record
<string, unknown
>) {
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
?? {};
21 Object.setPrototypeOf(this, new.target
.prototype
);
23 Error.captureStackTrace
? Error.captureStackTrace(this, this.constructor
) : (this.stack
= (new Error()).stack
);