diff --git a/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js b/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js index b6fca095..e1b5620f 100644 --- a/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js +++ b/lib/cartodb/models/mapconfig/adapter/analysis-mapconfig-adapter.js @@ -61,15 +61,15 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(user, requestMapConfi function createAnalysis(analysisDefinition, index, done) { self.analysisBackend.create(analysisConfiguration, analysisDefinition, function (err, analysis) { if (err) { - err.context = { - type: 'analysis', - analysis: { - index: index, - id: analysisDefinition.id, - type: analysisDefinition.type - } + var error = new Error(err.message); + error.type = 'analysis'; + error.context = {}; + error.context.layer = { + index: index, + id: analysisDefinition.id, + type: analysisDefinition.type }; - return done(err); + return done(error); } done(null, analysis); @@ -295,4 +295,4 @@ function AnalysisError(message) { this.message = message; } -require('util').inherits(AnalysisError, Error); \ No newline at end of file +require('util').inherits(AnalysisError, Error); diff --git a/test/acceptance/analysis/error-cases.js b/test/acceptance/analysis/error-cases.js index 5a2628eb..829f2d02 100644 --- a/test/acceptance/analysis/error-cases.js +++ b/test/acceptance/analysis/error-cases.js @@ -199,10 +199,14 @@ describe('analysis-layers error cases', function() { 'Analysis requires authentication with API key: permission denied.' ); - assert.equal(layergroupResult.errors_with_context[0].context.type, 'analysis'); - assert.equal(layergroupResult.errors_with_context[0].context.analysis.index, 0); - assert.equal(layergroupResult.errors_with_context[0].context.analysis.id, 'HEAD'); - assert.equal(layergroupResult.errors_with_context[0].context.analysis.type, 'buffer'); + assert.equal(layergroupResult.errors_with_context[0].type, 'analysis'); + assert.equal( + 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'); testClient.drain(done); }); @@ -252,10 +256,11 @@ describe('analysis-layers error cases', function() { 'Missing required param "radius"' ); - assert.equal(layergroupResult.errors_with_context[0].context.type, 'analysis'); - assert.equal(layergroupResult.errors_with_context[0].context.analysis.index, 0); - assert.equal(layergroupResult.errors_with_context[0].context.analysis.id, 'HEAD'); - assert.equal(layergroupResult.errors_with_context[0].context.analysis.type, 'buffer'); + 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'); testClient.drain(done); });