From d80f2b956600d7698bce5f4c057036cfb8e3ac7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Tue, 21 Jun 2016 18:26:10 +0200 Subject: [PATCH] Now errors with context have the same schema. --- .../adapter/analysis-mapconfig-adapter.js | 18 ++++++++-------- test/acceptance/analysis/error-cases.js | 21 ++++++++++++------- 2 files changed, 22 insertions(+), 17 deletions(-) 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); });