Merge branch 'standalone-server' into standalone-server-express-4
Conflicts: lib/cartodb/controllers/base.js
This commit is contained in:
commit
208dd209a4
@ -200,20 +200,24 @@ BaseController.prototype.sendError = function(req, res, err, label) {
|
|||||||
statusCode = 200;
|
statusCode = 200;
|
||||||
}
|
}
|
||||||
|
|
||||||
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/68
|
var errorResponseBody = { errors: [errorMessage(err)] };
|
||||||
var message = (_.isString(err) ? err : err.message) || 'Unknown error';
|
|
||||||
// Strip connection info, if any
|
|
||||||
message = message
|
|
||||||
// See https://github.com/CartoDB/Windshaft/issues/173
|
|
||||||
.replace(/Connection string: '[^']*'\\n/, '')
|
|
||||||
// See https://travis-ci.org/CartoDB/Windshaft/jobs/20703062#L1644
|
|
||||||
.replace(/is the server.*encountered/im, 'encountered');
|
|
||||||
|
|
||||||
var errorResponseBody = { errors: [message] };
|
|
||||||
|
|
||||||
this.send(req, res, errorResponseBody, statusCode);
|
this.send(req, res, errorResponseBody, statusCode);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function errorMessage(err) {
|
||||||
|
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/68
|
||||||
|
var message = (_.isString(err) ? err : err.message) || 'Unknown error';
|
||||||
|
|
||||||
|
// Strip connection info, if any
|
||||||
|
return message
|
||||||
|
// See https://github.com/CartoDB/Windshaft/issues/173
|
||||||
|
.replace(/Connection string: '[^']*'\n\s/im, '')
|
||||||
|
// See https://travis-ci.org/CartoDB/Windshaft/jobs/20703062#L1644
|
||||||
|
.replace(/is the server.*encountered/im, 'encountered');
|
||||||
|
}
|
||||||
|
module.exports.errorMessage = errorMessage;
|
||||||
|
|
||||||
function findStatusCode(err) {
|
function findStatusCode(err) {
|
||||||
var statusCode;
|
var statusCode;
|
||||||
if ( err.http_status ) {
|
if ( err.http_status ) {
|
||||||
|
@ -135,31 +135,4 @@ describe('regressions', function() {
|
|||||||
testClient.createLayergroup(mapConfig, { server: server }, completed);
|
testClient.createLayergroup(mapConfig, { server: server }, completed);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// See https://github.com/CartoDB/Windshaft/issues/173
|
|
||||||
it.skip("#173 does not send db details in connection error response", function(done) {
|
|
||||||
|
|
||||||
var mapConfig = testClient.defaultTableMapConfig('test_table');
|
|
||||||
|
|
||||||
var CustomOptions = _.clone(ServerOptions);
|
|
||||||
CustomOptions.grainstore = _.clone(CustomOptions.grainstore);
|
|
||||||
CustomOptions.grainstore.datasource = _.clone(CustomOptions.grainstore.datasource);
|
|
||||||
CustomOptions.grainstore.datasource.port = '666';
|
|
||||||
|
|
||||||
var options = {
|
|
||||||
statusCode: 400,
|
|
||||||
serverOptions: CustomOptions
|
|
||||||
};
|
|
||||||
|
|
||||||
testClient.createLayergroup(mapConfig, options, function(err, res, parsedBody) {
|
|
||||||
assert.ok(parsedBody.errors);
|
|
||||||
var msg = parsedBody.errors[0];
|
|
||||||
assert.ok(msg.match(/connect/), msg);
|
|
||||||
assert.ok(!msg.match(/666/), msg);
|
|
||||||
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
24
test/unit/cartodb/error_messages.test.js
Normal file
24
test/unit/cartodb/error_messages.test.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
require('../../support/test_helper');
|
||||||
|
|
||||||
|
var assert = require('assert');
|
||||||
|
|
||||||
|
var BaseController = require('../../../lib/cartodb/controllers/base');
|
||||||
|
|
||||||
|
describe('error messages clean up', function() {
|
||||||
|
|
||||||
|
// See https://github.com/CartoDB/Windshaft/issues/173
|
||||||
|
it("#173 does not send db details in connection error response", function() {
|
||||||
|
var inMessage = [
|
||||||
|
"Postgis Plugin: Bad connection",
|
||||||
|
"Connection string: 'host=127.0.0.1 port=5432 dbname=test_windshaft_cartodb_user_1_db " +
|
||||||
|
"user=test_windshaft_cartodb_user_1 connect_timeout=4'",
|
||||||
|
" encountered during parsing of layer 'layer0' in Layer"
|
||||||
|
].join('\n');
|
||||||
|
|
||||||
|
var outMessage = BaseController.errorMessage(inMessage);
|
||||||
|
|
||||||
|
assert.ok(outMessage.match('connect'), outMessage);
|
||||||
|
assert.ok(!outMessage.match(/666/), outMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user