UNPKG

@grubou/bussy

Version:

Command & query bus implementations

30 lines 1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoggingCommandBusMiddleware = void 0; class LoggingCommandBusMiddleware { constructor(logger, next) { this.logger = logger; this.next = next; } static build(logger) { return { chainWith(next) { return new LoggingCommandBusMiddleware(logger, next); } }; } async handle(command) { this.logger.info(`Executing command ${command.label()}`, { command }); try { const result = await this.next.handle(command); this.logger.info(`Success on command ${command.label()}`, { command }); return result; } catch (error) { this.logger.error(`Error on command ${command.label()}`, { error }); throw error; } } } exports.LoggingCommandBusMiddleware = LoggingCommandBusMiddleware; //# sourceMappingURL=LoggingCommandBusMiddleware.js.map