From 6bcf477532d4abf119f2c18342ecf76c35c6a109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Fri, 29 May 2020 16:06:16 +0200 Subject: [PATCH] Avoid custom headers to be undefined --- NEWS.md | 1 + lib/api/map/preview-template-controller.js | 4 +++- lib/api/middlewares/increment-map-view-count.js | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index e19c39aa..45dd9a29 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,7 @@ Announcements: - Remove `bootstrapFonts` at process startup (now done in `windshaft@6.0.0`) - Stop checking the installed version of some dependencies while testing - Send metrics about `map views` (#1162) +- Add custom headers in responses to allow to other components to be able to get insights about user activity. Bug Fixes: - Parsing date column in numeric histograms (#1160) diff --git a/lib/api/map/preview-template-controller.js b/lib/api/map/preview-template-controller.js index 10a40b93..d3c5884f 100644 --- a/lib/api/map/preview-template-controller.js +++ b/lib/api/map/preview-template-controller.js @@ -353,7 +353,9 @@ function incrementMapViews ({ metadataBackend }) { const statTag = mapConfig.obj().stat_tag; - res.set('Carto-Stat-Tag', `${statTag}`); + if (statTag) { + res.set('Carto-Stat-Tag', `${statTag}`); + } metadataBackend.incMapviewCount(user, statTag, (err) => { if (err) { diff --git a/lib/api/middlewares/increment-map-view-count.js b/lib/api/middlewares/increment-map-view-count.js index 20ddcf42..18adb34c 100644 --- a/lib/api/middlewares/increment-map-view-count.js +++ b/lib/api/middlewares/increment-map-view-count.js @@ -5,7 +5,9 @@ module.exports = function incrementMapViewCount (metadataBackend) { const { mapConfig, user } = res.locals; const statTag = mapConfig.obj().stat_tag; - res.set('Carto-Stat-Tag', `${statTag}`); + if (statTag) { + res.set('Carto-Stat-Tag', `${statTag}`); + } // Error won't blow up, just be logged. metadataBackend.incMapviewCount(user, statTag, (err) => {