Skip to content

Commit ccf66e9

Browse files
committed
Update middlewares.js
1 parent ad69d7c commit ccf66e9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/middlewares.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,21 @@ const handleRateLimit = async (req, res, next) => {
276276
if (pathExp.test(req.url)) {
277277
await limit.handler(req, res, err => {
278278
if (err) {
279-
throw err;
279+
if (err.code === Parse.Error.CONNECTION_FAILED) {
280+
throw err;
281+
}
282+
req.config.loggerController.error(
283+
'An unknown error occured when attempting to apply the rate limiter: ',
284+
err
285+
);
280286
}
281287
});
282288
}
283289
})
284290
);
285291
} catch (error) {
286292
res.status(429);
287-
res.json({ code: Parse.Error.CONNECTION_FAILED, error });
293+
res.json({ code: Parse.Error.CONNECTION_FAILED, error: error.message });
288294
return;
289295
}
290296
next();
@@ -477,7 +483,10 @@ export const addRateLimit = (route, config) => {
477483
max: route.requestCount,
478484
message: route.errorResponseMessage || RateLimitOptions.errorResponseMessage.default,
479485
handler: (request, response, next, options) => {
480-
throw options.message;
486+
throw {
487+
code: Parse.Error.CONNECTION_FAILED,
488+
message: options.message,
489+
};
481490
},
482491
skip: request => {
483492
if (request.ip === '127.0.0.1' && !route.includeInternalRequests) {
@@ -498,7 +507,7 @@ export const addRateLimit = (route, config) => {
498507
}
499508
}
500509
}
501-
return request.auth.isMaster;
510+
return request.auth?.isMaster;
502511
},
503512
keyGenerator: request => {
504513
return request.config.ip;

0 commit comments

Comments
 (0)