From b2cc7ab84fe150e17b745bb6f911fec9d8c13921 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 7 Mar 2018 14:53:13 +0100 Subject: [PATCH] Move functions to improve readablity --- lib/cartodb/controllers/layergroup.js | 82 +++++++++++++-------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/lib/cartodb/controllers/layergroup.js b/lib/cartodb/controllers/layergroup.js index 7010afa6..cc64cbe9 100644 --- a/lib/cartodb/controllers/layergroup.js +++ b/lib/cartodb/controllers/layergroup.js @@ -453,47 +453,6 @@ LayergroupController.prototype.layer = function (tileBackend) { }; }; -LayergroupController.prototype.incrementSuccessMetrics = function (statsClient) { - return function incrementSuccessMetricsMiddleware (req, res, next) { - const formatStat = parseFormat(req.params.format); - - statsClient.increment('windshaft.tiles.success'); - statsClient.increment(`windshaft.tiles.${formatStat}.success`); - - next(); - }; -}; - -LayergroupController.prototype.incrementErrorMetrics = function (statsClient) { - return function incrementErrorMetricsMiddleware (err, req, res, next) { - const formatStat = parseFormat(req.params.format); - - statsClient.increment('windshaft.tiles.error'); - statsClient.increment(`windshaft.tiles.${formatStat}.error`); - - next(err); - }; -}; - -LayergroupController.prototype.tileError = function () { - return function tileErrorMiddleware (err, req, res, next) { - // See https://github.com/Vizzuality/Windshaft-cartodb/issues/68 - let errMsg = err.message ? ( '' + err.message ) : ( '' + err ); - - // Rewrite mapnik parsing errors to start with layer number - const matches = errMsg.match("(.*) in style 'layer([0-9]+)'"); - - if (matches) { - errMsg = 'style' + matches[2] + ': ' + matches[1]; - } - - err.message = errMsg; - err.label = 'TILE RENDER'; - - next(err); - }; -}; - LayergroupController.prototype.center = function (previewBackend) { return function centerMiddleware (req, res, next) { const width = +req.params.width; @@ -653,6 +612,17 @@ LayergroupController.prototype.setSurrogateKeyHeader = function (surrogateKeysCa }; }; +LayergroupController.prototype.incrementSuccessMetrics = function (statsClient) { + return function incrementSuccessMetricsMiddleware (req, res, next) { + const formatStat = parseFormat(req.params.format); + + statsClient.increment('windshaft.tiles.success'); + statsClient.increment(`windshaft.tiles.${formatStat}.success`); + + next(); + }; +}; + LayergroupController.prototype.sendResponse = function () { return function sendResponseMiddleware (req, res) { req.profiler.done('res'); @@ -670,3 +640,33 @@ LayergroupController.prototype.sendResponse = function () { } }; }; + +LayergroupController.prototype.incrementErrorMetrics = function (statsClient) { + return function incrementErrorMetricsMiddleware (err, req, res, next) { + const formatStat = parseFormat(req.params.format); + + statsClient.increment('windshaft.tiles.error'); + statsClient.increment(`windshaft.tiles.${formatStat}.error`); + + next(err); + }; +}; + +LayergroupController.prototype.tileError = function () { + return function tileErrorMiddleware (err, req, res, next) { + // See https://github.com/Vizzuality/Windshaft-cartodb/issues/68 + let errMsg = err.message ? ( '' + err.message ) : ( '' + err ); + + // Rewrite mapnik parsing errors to start with layer number + const matches = errMsg.match("(.*) in style 'layer([0-9]+)'"); + + if (matches) { + errMsg = 'style' + matches[2] + ': ' + matches[1]; + } + + err.message = errMsg; + err.label = 'TILE RENDER'; + + next(err); + }; +};