diff --git a/lib/cartodb/controllers/map.js b/lib/cartodb/controllers/map.js index 2d65b801..901cc886 100644 --- a/lib/cartodb/controllers/map.js +++ b/lib/cartodb/controllers/map.js @@ -60,6 +60,7 @@ MapController.prototype.register = function(app) { this.prepareAdapterMapConfig.bind(this), this.createLayergroup.bind(this), this.createGet.bind(this), + respond, mapErrorMiddleware({ label: 'ANONYMOUS LAYERGROUP', augmentError: true @@ -74,6 +75,7 @@ MapController.prototype.register = function(app) { this.prepareAdapterMapConfig.bind(this), this.createLayergroup.bind(this), this.createPost.bind(this), + respond, mapErrorMiddleware({ label: 'ANONYMOUS LAYERGROUP', augmentError: true @@ -88,6 +90,7 @@ MapController.prototype.register = function(app) { this.getTemplate.bind(this), this.createLayergroupFromTemplate.bind(this), this.jsonp.bind(this), + respond, mapErrorMiddleware({ label: 'NAMED MAP LAYERGROUP' }) @@ -101,6 +104,7 @@ MapController.prototype.register = function(app) { this.getTemplate.bind(this), this.createLayergroupFromTemplate.bind(this), this.instantiate.bind(this), + respond, mapErrorMiddleware({ label: 'NAMED MAP LAYERGROUP' }) @@ -250,16 +254,7 @@ MapController.prototype.create = function(req, res, next) { if (err) { return next(err); } - - const { layergroup } = res.locals; - - res.status(200); - - if (req.query && req.query.callback) { - res.jsonp(layergroup); - } else { - res.json(layergroup); - } + next(); } ); }; @@ -333,20 +328,23 @@ MapController.prototype.instantiateTemplate = function(req, res, next) { if (err) { return next(err); } - - const { layergroup } = res.locals; - - res.status(200); - - if (req.query && req.query.callback) { - res.jsonp(layergroup); - } else { - res.json(layergroup); - } + next(); } ); }; +function respond (req, res) { + const { layergroup } = res.locals; + + res.status(200); + + if (req.query && req.query.callback) { + res.jsonp(layergroup); + } else { + res.json(layergroup); + } +} + MapController.prototype.afterLayergroupCreateBuilder = function (options = {}) { const self = this; const {