| 1 | import ChargingStation from '../ChargingStation'; |
| 2 | import { IncomingRequestCommand } from '../../types/ocpp/Requests'; |
| 3 | import { JsonType } from '../../types/JsonType'; |
| 4 | import getLogger from '../../utils/Logger'; |
| 5 | |
| 6 | export default abstract class OCPPIncomingRequestService { |
| 7 | protected chargingStation: ChargingStation; |
| 8 | |
| 9 | constructor(chargingStation: ChargingStation) { |
| 10 | this.chargingStation = chargingStation; |
| 11 | } |
| 12 | |
| 13 | protected handleIncomingRequestError<T>(commandName: IncomingRequestCommand, error: Error, errorOcppResponse?: T): T { |
| 14 | getLogger().error(this.chargingStation.logPrefix() + ' Incoming request command %s error: %j', commandName, error); |
| 15 | if (errorOcppResponse) { |
| 16 | return errorOcppResponse; |
| 17 | } |
| 18 | throw error; |
| 19 | } |
| 20 | |
| 21 | public abstract handleRequest(messageId: string, commandName: IncomingRequestCommand, commandPayload: JsonType): Promise<void>; |
| 22 | } |