Handle 'max waitingClients count exceeded' error as 429 Too many requests
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user