Fix error context, replaced turbo-carto error type by layer type. Context is no longer used, custom property for each type will be used instead.

This commit is contained in:
Daniel García Aubert 2016-06-26 18:43:04 +02:00
parent c2e0eb05e5
commit 016adb64ef
8 changed files with 30 additions and 26 deletions

View File

@ -242,11 +242,19 @@ function errorMessageWithContext(err) {
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/68
var message = (_.isString(err) ? err : err.message) || 'Unknown error';
return {
var error = {
type: err.type || 'unknown',
message: stripConnectionInfo(message),
context: err.context || 'unknown'
};
for (var prop in err) {
// type & message are properties from Error's prototype and will be skipped
if (err.hasOwnProperty(prop)) {
error[prop] = err[prop];
}
}
return error;
}
module.exports.errorMessage = errorMessage;

View File

@ -58,14 +58,12 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi
requestMapConfig = appendFiltersToNodes(requestMapConfig, dataviewsFiltersBySourceId);
function createAnalysis(analysisDefinition, index, done) {
function createAnalysis(analysisDefinition, done) {
self.analysisBackend.create(analysisConfiguration, analysisDefinition, function (err, analysis) {
if (err) {
var error = new Error(err.message);
error.type = 'analysis';
error.context = {};
error.context.layer = {
index: index,
error.analysis = {
id: analysisDefinition.id,
type: analysisDefinition.type
};
@ -77,8 +75,8 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi
}
var analysesQueue = queue(requestMapConfig.analyses.length);
requestMapConfig.analyses.forEach(function(analysis, index) {
analysesQueue.defer(createAnalysis, analysis, index);
requestMapConfig.analyses.forEach(function(analysis) {
analysesQueue.defer(createAnalysis, analysis);
});
analysesQueue.awaitAll(function(err, analysesResults) {

View File

@ -76,11 +76,11 @@ TurboCartoAdapter.prototype._parseCartoCss = function (username, params, layer,
if (err && err.name === 'TurboCartoError') {
var error = new Error('turbo-carto: ' + err.message);
error.http_status = 400;
error.type = 'turbo-carto';
error.context = err.context;
error.context.layer = {
error.type = 'layer';
error.layer = {
index: index,
type: layer.type
type: layer.type,
context: err.context
};
return callback(error);

View File

@ -204,9 +204,8 @@ describe('analysis-layers error cases', function() {
layergroupResult.errors_with_context[0].message,
'Analysis requires authentication with API key: permission denied.'
);
assert.equal(layergroupResult.errors_with_context[0].context.layer.index, 0);
assert.equal(layergroupResult.errors_with_context[0].context.layer.id, 'HEAD');
assert.equal(layergroupResult.errors_with_context[0].context.layer.type, 'buffer');
assert.equal(layergroupResult.errors_with_context[0].analysis.id, 'HEAD');
assert.equal(layergroupResult.errors_with_context[0].analysis.type, 'buffer');
testClient.drain(done);
});
@ -258,9 +257,8 @@ describe('analysis-layers error cases', function() {
assert.equal(layergroupResult.errors_with_context[0].type, 'analysis');
assert.equal(layergroupResult.errors_with_context[0].message, 'Missing required param "radius"');
assert.equal(layergroupResult.errors_with_context[0].context.layer.index, 0);
assert.equal(layergroupResult.errors_with_context[0].context.layer.id, 'HEAD');
assert.equal(layergroupResult.errors_with_context[0].context.layer.type, 'buffer');
assert.equal(layergroupResult.errors_with_context[0].analysis.id, 'HEAD');
assert.equal(layergroupResult.errors_with_context[0].analysis.type, 'buffer');
testClient.drain(done);
});

View File

@ -234,7 +234,7 @@ describe('attributes', function() {
'/**/ typeof test === \'function\' && ' +
'test({"errors":["Layer 0 has no exposed attributes"],' +
'"errors_with_context":[{' +
'"type":"unknown","message":"Layer 0 has no exposed attributes","context":"unknown"' +
'"type":"unknown","message":"Layer 0 has no exposed attributes"' +
'}]});'
);
return null;

View File

@ -61,7 +61,7 @@ describe('multilayer error cases', function() {
'/**/ typeof test === \'function\' && ' +
'test({"errors":["Missing layers array from layergroup config"],' +
'"errors_with_context":[{"type":"unknown",' +
'"message":"Missing layers array from layergroup config","context":"unknown"}]});'
'"message":"Missing layers array from layergroup config"}]});'
);
done();
});

View File

@ -114,16 +114,16 @@ describe('turbo-carto error cases', function() {
assert.ok(layergroup.hasOwnProperty('errors'));
assert.equal(layergroup.errors_with_context.length, 1);
assert.equal(layergroup.errors_with_context[0].type, 'turbo-carto');
assert.equal(layergroup.errors_with_context[0].type, 'layer');
assert.ok(layergroup.errors_with_context[0].message.match(/^turbo-carto/));
assert.ok(layergroup.errors_with_context[0].message.match(/unable\sto\scompute\sramp/i));
assert.ok(layergroup.errors_with_context[0].message.match(/wadus_column/));
assert.equal(layergroup.errors_with_context[0].context.layer.index, 0);
assert.equal(layergroup.errors_with_context[0].context.layer.type, 'mapnik');
assert.equal(layergroup.errors_with_context[0].layer.index, 0);
assert.equal(layergroup.errors_with_context[0].layer.type, 'mapnik');
assert.equal(layergroup.errors_with_context[0].context.selector, '#populated_places_simple_reduced');
assert.deepEqual(layergroup.errors_with_context[0].context.source, {
assert.equal(layergroup.errors_with_context[0].layer.context.selector, '#populated_places_simple_reduced');
assert.deepEqual(layergroup.errors_with_context[0].layer.context.source, {
start: {
line: 10,
column: 3

View File

@ -87,7 +87,7 @@ describe('turbo-carto regressions', function() {
var turboCartoError = layergroup.errors_with_context[0];
assert.ok(turboCartoError);
assert.equal(turboCartoError.type, 'turbo-carto');
assert.equal(turboCartoError.type, 'layer');
assert.ok(turboCartoError.message.match(/permission\sdenied\sfor\srelation\stest_table_private_1/));
done();