Merge pull request #988 from CartoDB/984-sql-timeout-error-message

984 limits error messages
This commit is contained in:
Eneko Lakasta 2018-07-03 16:44:58 +02:00 committed by GitHub
commit c1671abaa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 32 deletions

View File

@ -47,6 +47,9 @@ Bug Fixes:
- Fix `meta.stats.estimatedFeatureCount` for aggregations and queries with tokens
- Static maps filters correctly if `layer` option is passed in the url.
Announcements:
* Improve error message when the DB query is over the user's limits
## 6.1.0
Released 2018-04-16

View File

@ -46,26 +46,39 @@ function isDatasourceTimeoutError (err) {
return err.message && err.message.match(/canceling statement due to statement timeout/i);
}
function isTimeoutError (err) {
return isRenderTimeoutError(err) || isDatasourceTimeoutError(err);
function isTimeoutError (errorTypes) {
return errorTypes.renderTimeoutError || errorTypes.datasourceTimeoutError;
}
function getErrorTypes(error) {
return {
renderTimeoutError: isRenderTimeoutError(error),
datasourceTimeoutError: isDatasourceTimeoutError(error),
};
}
function populateTimeoutErrors (errors) {
return errors.map(function (error) {
if (isRenderTimeoutError(error)) {
error.subtype = 'render';
}
const errorTypes = getErrorTypes(error);
if (isDatasourceTimeoutError(error)) {
error.subtype = 'datasource';
}
if (isTimeoutError(error)) {
if (isTimeoutError(errorTypes)) {
error.message = 'You are over platform\'s limits. Please contact us to know more details';
error.type = 'limit';
error.http_status = 429;
}
if (errorTypes.datasourceTimeoutError) {
error.subtype = 'datasource';
error.message = 'You are over platform\'s limits: SQL query timeout error.' +
' Refactor your query before running again or contact CARTO support for more details.';
}
if (errorTypes.renderTimeoutError) {
error.subtype = 'render';
error.message = 'You are over platform\'s limits: Render timeout error.' +
' Contact CARTO support for more details.';
}
return error;
});
}

View File

@ -47,7 +47,8 @@ function rateLimit(userLimitsBackend, endpointGroup = null) {
res.set('Retry-After', retry + 1);
let rateLimitError = new Error(
'You are over platform\'s limits. Please contact us to know more details'
'You are over platform\'s limits: too many requests.' +
' Please contact us to know more details'
);
rateLimitError.http_status = 429;
rateLimitError.type = 'limit';

View File

@ -144,7 +144,8 @@ function assertRateLimitRequest (status, limit, remaining, reset, retry, done) {
assert.ifError(err);
} else {
assert.ok(err);
assert.equal(err.message, 'You are over platform\'s limits. Please contact us to know more details');
assert.equal(err.message, 'You are over platform\'s limits: too many requests.' +
' Please contact us to know more details');
assert.equal(err.http_status, 429);
assert.equal(err.type, 'limit');
assert.equal(err.subtype, 'rate-limit');

View File

@ -68,12 +68,15 @@ const createMapConfig = ({
}
});
const db_limit_error_message = 'You are over platform\'s limits: SQL query timeout error.' +
' Refactor your query before running again or contact CARTO support for more details.';
const DATASOURCE_TIMEOUT_ERROR = {
errors: ['You are over platform\'s limits. Please contact us to know more details'],
errors: [db_limit_error_message],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform\'s limits. Please contact us to know more details'
message: db_limit_error_message
}]
};
@ -141,11 +144,11 @@ describe('user database timeout limit', function () {
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors: [db_limit_error_message ],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform\'s limits. Please contact us to know more details',
message: db_limit_error_message,
layer: { id: 'layer0', index: 0, type: 'mapnik' }
}]
});
@ -363,11 +366,11 @@ describe('user database timeout limit', function () {
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors: [ db_limit_error_message ],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform\'s limits. Please contact us to know more details',
message: db_limit_error_message,
layer: { id: 'layer0', index: 0, type: 'mapnik' }
}]
});
@ -541,11 +544,11 @@ describe('user database timeout limit', function () {
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors: [ db_limit_error_message ],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform\'s limits. Please contact us to know more details',
message: db_limit_error_message,
layer: { id: 'layer0', index: 0, type: 'mapnik' }
}]
});
@ -645,11 +648,11 @@ describe('user database timeout limit', function () {
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors: [db_limit_error_message],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform\'s limits. Please contact us to know more details',
message: db_limit_error_message,
layer: { id: 'torque-layer0', index: 0, type: 'torque' }
}]
});
@ -776,11 +779,11 @@ describe('user database timeout limit', function () {
this.testClient.getLayergroup({ response: expectedResponse }, (err, timeoutError) => {
assert.deepEqual(timeoutError, {
errors: [ 'You are over platform\'s limits. Please contact us to know more details' ],
errors: [db_limit_error_message],
errors_with_context: [{
type: 'limit',
subtype: 'datasource',
message: 'You are over platform\'s limits. Please contact us to know more details',
message: db_limit_error_message,
layer: {
id: 'layer0',
index: 0,

View File

@ -23,6 +23,9 @@ const validationPointSleepSql = `
2 val
`;
const renderTimeoutErrorMessage = 'You are over platform\'s limits: Render timeout error.' +
' Contact CARTO support for more details.';
const createMapConfig = ({
version = '1.6.0',
type = 'cartodb',
@ -96,11 +99,11 @@ describe('user render timeout limit', function () {
assert.ifError(err);
assert.deepEqual(timeoutError, {
errors: ["You are over platform\'s limits. Please contact us to know more details"],
errors: [renderTimeoutErrorMessage],
errors_with_context: [{
type: 'limit',
subtype: 'render',
message: "You are over platform\'s limits. Please contact us to know more details",
message: renderTimeoutErrorMessage,
layer: {
id: "layer0",
index: 0,
@ -188,11 +191,11 @@ describe('user render timeout limit', function () {
assert.ifError(err);
assert.deepEqual(timeoutError, {
errors: ["You are over platform\'s limits. Please contact us to know more details"],
errors: [renderTimeoutErrorMessage],
errors_with_context: [{
type: 'limit',
subtype: 'render',
message: "You are over platform\'s limits. Please contact us to know more details"
message: renderTimeoutErrorMessage
}]
});
@ -282,11 +285,11 @@ describe('user render timeout limit', function () {
assert.ifError(err);
assert.deepEqual(tile, {
errors: ['You are over platform\'s limits. Please contact us to know more details'],
errors: [renderTimeoutErrorMessage],
errors_with_context: [{
type: 'limit',
subtype: 'render',
message: 'You are over platform\'s limits. Please contact us to know more details'
message: renderTimeoutErrorMessage
}]
});
@ -384,11 +387,11 @@ describe('user render timeout limit', function () {
assert.ifError(err);
assert.deepEqual(timeoutError, {
errors: ["You are over platform\'s limits. Please contact us to know more details"],
errors: [renderTimeoutErrorMessage],
errors_with_context: [{
type: 'limit',
subtype: 'render',
message: "You are over platform\'s limits. Please contact us to know more details"
message: renderTimeoutErrorMessage
}]
});