Return multiple turbo-carto errors

Closes #541
This commit is contained in:
Raul Ochoa
2016-07-06 00:32:30 +02:00
parent 9cf856ab78
commit b3107916ce
3 changed files with 68 additions and 6 deletions
@@ -32,12 +32,22 @@ TurboCartoAdapter.prototype.getMapConfig = function (user, requestMapConfig, par
parseCartoQueue.defer(self._parseCartoCss.bind(self), user, params, layer, index, layerId);
});
parseCartoQueue.awaitAll(function (err, layers) {
parseCartoQueue.awaitAll(function (err, results) {
if (err) {
return callback(err);
}
requestMapConfig.layers = layers;
var errors = results.reduce(function(errors, result) {
if (result.error) {
errors.push(result.error);
}
return errors;
}, []);
if (errors.length > 0) {
return callback(errors);
}
requestMapConfig.layers = results.map(function(result) { return result.layer; });
return callback(null, requestMapConfig);
});
@@ -70,7 +80,7 @@ var tokensQueryTpl = dot.template([
TurboCartoAdapter.prototype._parseCartoCss = function (username, params, layer, layerIndex, layerId, callback) {
if (!shouldParseLayerCartocss(layer)) {
return callback(null, layer);
return callback(null, { layer: layer });
}
var pg = new PSQL(dbParamsFromReqParams(params));
@@ -88,14 +98,14 @@ TurboCartoAdapter.prototype._parseCartoCss = function (username, params, layer,
context: err.context
};
return callback(error);
return callback(null, { error: error });
}
// Try to continue in the rest of the cases
if (cartocss) {
layer.options.cartocss = cartocss;
}
return callback(null, layer);
return callback(null, { layer: layer });
}
var layerSql = layer.options.sql;
@@ -107,7 +117,7 @@ TurboCartoAdapter.prototype._parseCartoCss = function (username, params, layer,
if (err) {
var error = new Error('turbo-carto: ' + err.message);
error.type = 'turbo-carto';
return callback(error);
return processCallback(error);
}
resultSet = resultSet || {};