Let to the caller to choose how to handle the call to a method

This commit is contained in:
Daniel García Aubert
2020-04-27 13:27:05 +02:00
parent e90c196598
commit 1bbde4f5e3
2 changed files with 6 additions and 10 deletions
+4 -2
View File
@@ -3,7 +3,7 @@
const EVENT_VERSION = '1';
const MAX_LENGTH = 100;
function pubSubMetrics ({ enabled, metricsBackend }) {
function pubSubMetrics ({ enabled, metricsBackend, logger }) {
if (!enabled) {
return function pubSubMetricsDisabledMiddleware (req, res, next) {
next();
@@ -15,7 +15,9 @@ function pubSubMetrics ({ enabled, metricsBackend }) {
const { event, attributes } = getEventData(req, res);
if (event) {
metricsBackend.send(event, attributes);
metricsBackend.send(event, attributes)
.then(() => logger.debug(`PubSubTracker: event '${event}' published succesfully`))
.catch((error) => logger.error(`ERROR: pubsub middleware failed to publish event '${event}': ${error.message}`));
}
});