Commit | Line | Data |
---|---|---|
14763b46 JB |
1 | import { ErrorType } from '../../types/ocpp/ErrorType'; |
2 | import { IncomingRequestCommand } from '../../types/ocpp/Requests'; | |
3 | ||
4 | export default class OCPPError extends Error { | |
5 | code: ErrorType | IncomingRequestCommand; | |
6 | details?: unknown; | |
7 | ||
8 | constructor(code: ErrorType | IncomingRequestCommand, message: string, details?: unknown) { | |
9 | super(message); | |
10 | ||
11 | this.name = new.target.name; | |
12 | this.code = code ?? ErrorType.GENERIC_ERROR; | |
13 | this.message = message ?? ''; | |
14 | this.details = details ?? {}; | |
15 | ||
16 | Object.setPrototypeOf(this, new.target.prototype); | |
17 | ||
18 | Error.captureStackTrace ? Error.captureStackTrace(this, this.constructor) : (this.stack = (new Error()).stack); | |
19 | } | |
20 | } |