Prevent from uncaught exception: Range filter Error from camshaft when getting analysis query

This commit is contained in:
Daniel García Aubert 2018-10-22 15:26:59 +02:00
parent 211e815d9c
commit 12d58f3af2

View File

@ -107,24 +107,32 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi
return sourceId2Query;
}, {});
var missingNodesErrors = [];
var analysesErrors = [];
requestMapConfig.layers = requestMapConfig.layers.map(function(layer, layerIndex) {
if (getLayerSourceId(layer)) {
var layerSourceId = getLayerSourceId(layer);
var layerNode = sourceId2Node[layerSourceId];
if (layerNode) {
var analysisSql = layerQuery(layerNode);
var sqlQueryWrap = layer.options.sql_wrap;
if (sqlQueryWrap) {
layer.options.sql_raw = analysisSql;
analysisSql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, analysisSql);
try {
var analysisSql;
// it might throw error: Range filter from camshaft, for instance.
analysisSql = layerQuery(layerNode);
var sqlQueryWrap = layer.options.sql_wrap;
if (sqlQueryWrap) {
layer.options.sql_raw = analysisSql;
analysisSql = sqlQueryWrap.replace(/<%=\s*sql\s*%>/g, analysisSql);
}
layer.options.sql = analysisSql;
layer.options.columns = getDataviewsColumns(getLayerDataviews(layer, dataviews));
layer.options.affected_tables = getAllAffectedTablesFromSourceNodes(layerNode);
} catch (error) {
analysesErrors.push(error);
}
layer.options.sql = analysisSql;
layer.options.columns = getDataviewsColumns(getLayerDataviews(layer, dataviews));
layer.options.affected_tables = getAllAffectedTablesFromSourceNodes(layerNode);
} else {
missingNodesErrors.push(
analysesErrors.push(
new Error('Missing analysis node.id="' + layerSourceId +'" for layer='+layerIndex)
);
}
@ -133,8 +141,8 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi
});
var missingDataviewsNodesErrors = getMissingDataviewsSourceIds(dataviews, sourceId2Node);
if (missingNodesErrors.length > 0 || missingDataviewsNodesErrors.length > 0) {
return callback(missingNodesErrors.concat(missingDataviewsNodesErrors));
if (analysesErrors.length > 0 || missingDataviewsNodesErrors.length > 0) {
return callback(analysesErrors.concat(missingDataviewsNodesErrors));
}
// Augment dataviews with sql from analyses