Improve error handling
This commit is contained in:
parent
32938eeab7
commit
92e62069d4
@ -22,13 +22,22 @@ module.exports = class ClusterBackend {
|
|||||||
const { user, token, layer: layerIndex } = params;
|
const { user, token, layer: layerIndex } = params;
|
||||||
const mapConfig = new AggregationMapConfig(user, _mapConfig.obj(), pg);
|
const mapConfig = new AggregationMapConfig(user, _mapConfig.obj(), pg);
|
||||||
|
|
||||||
if (!mapConfig.isAggregationLayer(layerIndex)) {
|
const layer = mapConfig.getLayer(layerIndex);
|
||||||
|
|
||||||
|
if (layer.options.aggregation === false || !mapConfig.isAggregationLayer(layerIndex)) {
|
||||||
const error = new Error(`Map ${token} has no aggregation defined for layer ${layerIndex}`);
|
const error = new Error(`Map ${token} has no aggregation defined for layer ${layerIndex}`);
|
||||||
|
error.http_status = 400;
|
||||||
|
error.type = 'layer';
|
||||||
|
error.subtype = 'aggregation';
|
||||||
|
error.layer = {
|
||||||
|
index: layerIndex,
|
||||||
|
type: layer.type
|
||||||
|
};
|
||||||
|
|
||||||
debug(error);
|
debug(error);
|
||||||
return callback(error);
|
return callback(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const layer = mapConfig.getLayer(layerIndex);
|
|
||||||
const query = layer.options.sql_raw;
|
const query = layer.options.sql_raw;
|
||||||
const resolution = layer.options.aggregation.resolution || 1;
|
const resolution = layer.options.aggregation.resolution || 1;
|
||||||
|
|
||||||
|
@ -61,11 +61,59 @@ describe('cluster', function () {
|
|||||||
errors:[ 'Map d725a568ab961af8197d311eececb83a has no aggregation defined for layer 0' ],
|
errors:[ 'Map d725a568ab961af8197d311eececb83a has no aggregation defined for layer 0' ],
|
||||||
errors_with_context:[
|
errors_with_context:[
|
||||||
{
|
{
|
||||||
type: 'unknown',
|
layer: {
|
||||||
message: 'Map d725a568ab961af8197d311eececb83a has no aggregation defined for layer 0'
|
index: '0',
|
||||||
|
type: 'cartodb'
|
||||||
|
},
|
||||||
|
message: 'Map d725a568ab961af8197d311eececb83a has no aggregation defined for layer 0',
|
||||||
|
subtype: 'aggregation',
|
||||||
|
type: 'layer'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testClient.drain(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('with aggregation disabled should return error while fetching disaggregated features', function (done) {
|
||||||
|
const mapConfig = createVectorMapConfig([{
|
||||||
|
type: 'cartodb',
|
||||||
|
options: {
|
||||||
|
sql: POINTS_SQL_1,
|
||||||
|
aggregation: false
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
const testClient = new TestClient(mapConfig);
|
||||||
|
const zoom = 0;
|
||||||
|
const cartodb_id = 1;
|
||||||
|
const layerId = 0;
|
||||||
|
const params = {
|
||||||
|
response: {
|
||||||
|
status: 400
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
testClient.getClusterFeatures(zoom, cartodb_id, layerId, params, (err, body) => {
|
||||||
|
if (err) {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.deepStrictEqual(body, {
|
||||||
|
errors:[ 'Map 3a09728f8c08444820336ea9983ce92b has no aggregation defined for layer 0' ],
|
||||||
|
errors_with_context:[
|
||||||
|
{
|
||||||
|
layer: {
|
||||||
|
index: '0',
|
||||||
|
type: 'cartodb'
|
||||||
|
},
|
||||||
|
message: 'Map 3a09728f8c08444820336ea9983ce92b has no aggregation defined for layer 0',
|
||||||
|
subtype: 'aggregation',
|
||||||
|
type: 'layer'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
testClient.drain(done);
|
testClient.drain(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user