diff --git a/lib/cartodb/controllers/base.js b/lib/cartodb/controllers/base.js index b1b8bf6a..4ce9af17 100644 --- a/lib/cartodb/controllers/base.js +++ b/lib/cartodb/controllers/base.js @@ -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; diff --git a/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js index e1b5620f..4cc9be53 100644 --- a/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js @@ -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) { diff --git a/lib/cartodb/models/mapconfig/adapter/turbo-carto-adapter.js b/lib/cartodb/models/mapconfig/adapter/turbo-carto-adapter.js index 8efaf5a6..54deb15f 100644 --- a/lib/cartodb/models/mapconfig/adapter/turbo-carto-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/turbo-carto-adapter.js @@ -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); diff --git a/test/acceptance/analysis/error-cases.js b/test/acceptance/analysis/error-cases.js index 829f2d02..897cb02c 100644 --- a/test/acceptance/analysis/error-cases.js +++ b/test/acceptance/analysis/error-cases.js @@ -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); }); diff --git a/test/acceptance/ported/attributes.js b/test/acceptance/ported/attributes.js index 5478bbb6..04b48826 100644 --- a/test/acceptance/ported/attributes.js +++ b/test/acceptance/ported/attributes.js @@ -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; diff --git a/test/acceptance/ported/multilayer_error_cases.js b/test/acceptance/ported/multilayer_error_cases.js index 9d59a5b3..057f7892 100644 --- a/test/acceptance/ported/multilayer_error_cases.js +++ b/test/acceptance/ported/multilayer_error_cases.js @@ -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(); }); diff --git a/test/acceptance/turbo-cartocss/error-cases.js b/test/acceptance/turbo-cartocss/error-cases.js index 8582d753..17dcc847 100644 --- a/test/acceptance/turbo-cartocss/error-cases.js +++ b/test/acceptance/turbo-cartocss/error-cases.js @@ -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 diff --git a/test/acceptance/turbo-cartocss/regressions.js b/test/acceptance/turbo-cartocss/regressions.js index a298ffac..6a35249b 100644 --- a/test/acceptance/turbo-cartocss/regressions.js +++ b/test/acceptance/turbo-cartocss/regressions.js @@ -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();