Handle 'max waitingClients count exceeded' error as 429 Too many requests

This commit is contained in:
Daniel García Aubert
2019-01-30 10:27:00 +01:00
parent c4576564e5
commit d70a87b299
@@ -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)) {