Commit | Line | Data |
---|---|---|
a6b3c6c3 JB |
1 | import { IncomingRequestCommand, RequestCommand } from '../../types/ocpp/Requests'; |
2 | ||
14763b46 | 3 | import { ErrorType } from '../../types/ocpp/ErrorType'; |
14763b46 JB |
4 | |
5 | export default class OCPPError extends Error { | |
6 | code: ErrorType | IncomingRequestCommand; | |
a6b3c6c3 | 7 | command?: RequestCommand | IncomingRequestCommand; |
ae8ee665 | 8 | details?: Record<string, unknown>; |
14763b46 | 9 | |
ae8ee665 | 10 | constructor(code: ErrorType | IncomingRequestCommand, message: string, command?: RequestCommand | IncomingRequestCommand, details?: Record<string, unknown>) { |
14763b46 JB |
11 | super(message); |
12 | ||
13 | this.name = new.target.name; | |
14 | this.code = code ?? ErrorType.GENERIC_ERROR; | |
15 | this.message = message ?? ''; | |
9292e32a | 16 | this.command = 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 | } |