Move functions to improve readablity

This commit is contained in:
Daniel García Aubert 2018-03-07 14:53:13 +01:00
parent eb3414f07f
commit b2cc7ab84f

View File

@ -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);
};
};