From d70a87b299ad96fbc98418a0e711c903ac37f7bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Wed, 30 Jan 2019 10:27:00 +0100 Subject: [PATCH] Handle 'max waitingClients count exceeded' error as 429 Too many requests --- lib/cartodb/api/middlewares/error-middleware.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/cartodb/api/middlewares/error-middleware.js b/lib/cartodb/api/middlewares/error-middleware.js index a81c87a0..e1f2e111 100644 --- a/lib/cartodb/api/middlewares/error-middleware.js +++ b/lib/cartodb/api/middlewares/error-middleware.js @@ -9,7 +9,7 @@ module.exports = function errorMiddleware (/* options */) { // jshint maxcomplexity:9 var allErrors = Array.isArray(err) ? err : [err]; - allErrors = populateTimeoutErrors(allErrors); + allErrors = populateLimitErrors(allErrors); const label = err.label || 'UNKNOWN'; err = allErrors[0] || new Error(label); @@ -59,8 +59,21 @@ function getErrorTypes(error) { }; } -function populateTimeoutErrors (errors) { +function isMaxWaitingClientsError (err) { + return err.message === 'max waitingClients count exceeded'; +} + +function populateLimitErrors (errors) { return errors.map(function (error) { + if (isMaxWaitingClientsError(error)) { + error.message = 'You are over platform\'s limits: Max render capacity exceeded' + + ' Contact CARTO support for more details.'; + error.type = 'limit'; + error.http_status = 429; + + return error; + } + const errorTypes = getErrorTypes(error); if (isTimeoutError(errorTypes)) {