Logs with console.error too large row erros

This commit is contained in:
Raul Ochoa 2015-03-02 12:31:11 +01:00
parent 296bb658bf
commit 45f5b398a0
2 changed files with 47 additions and 1 deletions

View File

@ -33,6 +33,13 @@ PostgresFormat.prototype.handleQueryRowWithSkipFields = function(row, result) {
this.handleQueryRow(row, result);
};
PostgresFormat.prototype.handleQueryError = function(err) {
this.error = err;
if (err.message && err.message.match(/row too large, was \d* bytes/i)) {
console.error(JSON.stringify({error: err.message}));
}
};
PostgresFormat.prototype.handleNotice = function(msg, result) {
if ( ! result.notices ) result.notices = [];
for (var i=0; i<msg.length; i++) {
@ -125,7 +132,7 @@ PostgresFormat.prototype.sendResponse = function(opts, callback) {
query.on('row', that.handleQueryRow.bind(that));
}
query.on('end', that.handleQueryEnd.bind(that));
query.on('error', function(err) { that.error = err; });
query.on('error', that.handleQueryError.bind(that));
query.on('notice', function(msg) {
that.handleNotice(msg, query._result);
});

View File

@ -1464,4 +1464,43 @@ test('GET with callback must return 200 status error even if it is an error', fu
);
});
test('too large rows get into error log', function(done){
var dbMaxRowSize = global.settings.db_max_row_size;
global.settings.db_max_row_size = 4;
var consoleErrorFn = console.error;
var hit = false;
var consoleError;
console.error = function(what) {
hit = true;
consoleError = what;
};
assert.response(
app,
{
url: "/api/v1/sql?" + querystring.stringify({
q: "SELECT * FROM untitle_table_4"
}),
headers: {
host: 'vizzuality.cartodb.com'
},
method: 'GET'
},
{
status: 400
},
function() {
assert.equal(hit, true);
assert.ok(JSON.parse(consoleError).error.match(/^row too large.*/i), "Expecting row size limit error");
global.settings.db_max_row_size = dbMaxRowSize;
console.error = consoleErrorFn;
done();
}
);
});
});