Merge pull request #519 from CartoDB/fix-error-with-context

Now errors with context have the same schema.
This commit is contained in:
Daniel 2016-06-21 18:41:46 +02:00 committed by GitHub
commit 256032ca4a
2 changed files with 22 additions and 17 deletions

View File

@ -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);

View File

@ -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);
});