Set platform limits message on streaming responses too

This commit is contained in:
Raul Marin 2019-01-02 16:15:28 +01:00
parent 4662077a02
commit 03701ae695
3 changed files with 69 additions and 52 deletions

View File

@ -3,6 +3,7 @@
var _ = require('underscore');
var pg = require('./../pg');
const errorHandlerFactory = require('../../../services/error_handler_factory');
function GeoJsonFormat() {
this.buffer = '';
@ -72,7 +73,7 @@ GeoJsonFormat.prototype.handleQueryEnd = function(/*result*/) {
this.buffer += ']'; // end of features
if (this.error) {
this.buffer += ',"error":' + JSON.stringify([this.error.message]);
this.buffer += ',"error":' + JSON.stringify(errorHandlerFactory(this.error).getResponse().error);
}
this.buffer += '}'; // end of root object

View File

@ -3,6 +3,7 @@
var _ = require('underscore');
var pg = require('./../pg');
const errorHandlerFactory = require('../../../services/error_handler_factory');
function JsonFormat() {
this.buffer = '';
@ -131,7 +132,7 @@ JsonFormat.prototype.handleQueryEnd = function(result) {
];
if (this.error) {
out.push(',"error":', JSON.stringify([this.error.message]));
out.push(',"error":', JSON.stringify(errorHandlerFactory(this.error).getResponse().error));
}

View File

@ -771,59 +771,74 @@ it('GET with callback must return 200 status error even if it is an error', func
});
});
it('GET with slow query exceeding statement timeout returns proper error message', function(done){
assert.response(server, {
url: "/api/v1/sql?q=select%20pg_sleep(2.1)%20as%20sleep",
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},
{
status: 429,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
},
function(err, res) {
var error = JSON.parse(res.body);
assert.deepEqual(error, {
error: [
'You are over platform\'s limits: SQL query timeout error.' +
' Refactor your query before running again or contact CARTO support for more details.',
],
context: 'limit',
detail: 'datasource'
});
it('GET with slow query exceeding statement timeout returns proper error message', function(done){
assert.response(server, {
url: "/api/v1/sql?q=select%20pg_sleep(2.1)%20as%20sleep",
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},
{
// status: 429, ---> Both 200 and 429 are valid
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
},
function(err, res) {
var error = JSON.parse(res.body);
assert.deepEqual(error.error, [
'You are over platform\'s limits: SQL query timeout error.' +
' Refactor your query before running again or contact CARTO support for more details.'
]);
done();
});
});
done();
});
});
it('GET with slow python script exceeding statement timeout returns proper error message', function(done){
assert.response(server, {
url: "/api/v1/sql?q=select%20py_sleep(2.1)",
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},
{
status: 429,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
},
function(err, res) {
var error = JSON.parse(res.body);
assert.deepEqual(error, {
error: [
'You are over platform\'s limits: SQL query timeout error.' +
' Refactor your query before running again or contact CARTO support for more details.',
],
context: 'limit',
detail: 'datasource'
});
it('GET with slow query exceeding statement timeout returns proper error message (streaming)', function(done){
assert.response(server, {
url: "/api/v1/sql?q=SELECT%20pg_sleep(generate_series(2,10)/10.0)",
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},
{
// status: 429, ---> Both 200 and 429 are valid
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
},
function(err, res) {
var error = JSON.parse(res.body);
assert.deepEqual(error.error, [
'You are over platform\'s limits: SQL query timeout error.' +
' Refactor your query before running again or contact CARTO support for more details.'
]);
done();
});
});
done();
});
});
it('GET with slow python script exceeding statement timeout returns proper error message', function(done){
assert.response(server, {
url: "/api/v1/sql?q=select%20py_sleep(2.1)",
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},
{
// status: 429, ---> Both 200 and 429 are valid
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
},
function(err, res) {
var error = JSON.parse(res.body);
assert.deepEqual(error.error, [
'You are over platform\'s limits: SQL query timeout error.' +
' Refactor your query before running again or contact CARTO support for more details.'
]);
done();
});
});
it('too large rows get into error log', function(done){