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