From 5974413d5cead17efc5cdca3d6d0b77e4500d1d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Mon, 31 Jul 2017 19:08:29 +0200 Subject: [PATCH] Use 429 to indicate timeout errors --- lib/cartodb/controllers/base.js | 7 +++++++ test/acceptance/user-database-timeout-limit.js | 10 +++++----- test/acceptance/user-render-timeout-limit.js | 8 ++++---- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/cartodb/controllers/base.js b/lib/cartodb/controllers/base.js index b8b73569..c5afdecb 100644 --- a/lib/cartodb/controllers/base.js +++ b/lib/cartodb/controllers/base.js @@ -301,5 +301,12 @@ function statusFromErrorMessage(errMsg) { statusCode = 404; } } + else if ( -1 !== errMsg.indexOf('Render timed out') ) { + statusCode = 429; // under discussion + } + else if ( -1 !== errMsg.indexOf('canceling statement due to statement timeout') ) { + statusCode = 429; // under discussion + } + return statusCode; } diff --git a/test/acceptance/user-database-timeout-limit.js b/test/acceptance/user-database-timeout-limit.js index 35add015..53b69775 100644 --- a/test/acceptance/user-database-timeout-limit.js +++ b/test/acceptance/user-database-timeout-limit.js @@ -75,7 +75,7 @@ describe('user database timeout limit', function () { it('layergroup creation works but dataview request fails due to statement timeout', function (done) { const params = { response: { - status: 400, + status: 429, headers: { 'Content-Type': 'application/json; charset=utf-8' } @@ -117,7 +117,7 @@ describe('user database timeout limit', function () { it('fails due to statement timeout', function (done) { const expectedResponse = { - status: 400, + status: 429, headers: { 'Content-Type': 'application/json; charset=utf-8' } @@ -182,7 +182,7 @@ describe('user database timeout limit', function () { format: 'torque.json', layers: [ 0 ], response: { - status: 400, + status: 429, headers: { 'Content-Type': 'application/json; charset=utf-8' } @@ -231,7 +231,7 @@ describe('user database timeout limit', function () { it('layergroup creation fails due to statement timeout', function (done) { const expectedResponse = { - status: 400, + status: 429, headers: { 'Content-Type': 'application/json; charset=utf-8' } @@ -304,7 +304,7 @@ describe('user database timeout limit', function () { featureId: 1, layer: 0, response: { - status: 400, + status: 429, headers: { 'Content-Type': 'application/json; charset=utf-8' } diff --git a/test/acceptance/user-render-timeout-limit.js b/test/acceptance/user-render-timeout-limit.js index cd5b03a7..e579a132 100644 --- a/test/acceptance/user-render-timeout-limit.js +++ b/test/acceptance/user-render-timeout-limit.js @@ -85,7 +85,7 @@ describe('user render timeout limit', function () { it('layergroup creation fails due to statement timeout', function (done) { const expectedResponse = { - status: 400, + status: 429, headers: { 'Content-Type': 'application/json; charset=utf-8' } @@ -174,7 +174,7 @@ describe('user render timeout limit', function () { it('layergroup creation works and render tile fails', function (done) { var params = { response: { - status: 400, + status: 429, headers: { 'Content-Type': 'application/json; charset=utf-8' } @@ -211,7 +211,7 @@ describe('user render timeout limit', function () { const params = { format: 'mvt', response: { - status: 400, + status: 429, headers: { 'Content-Type': 'application/json; charset=utf-8' } @@ -252,7 +252,7 @@ describe('user render timeout limit', function () { layers: 'mapnik', format: 'grid.json', response: { - status: 400, + status: 429, headers: { 'Content-Type': 'application/x-protobuf' }