fix(logs): Logging the result of rate limiting

This commit is contained in:
Chris Troutner
2022-03-28 14:52:43 -07:00
parent e7e9723783
commit d4df475eee
2 changed files with 19 additions and 3 deletions
+1 -1
View File
@@ -40,7 +40,7 @@ const logReqInfo = function (req, res, next) {
body: req.body
}
wlogger.verbose(`Request: ${ip} ${method} ${url}`, dataToLog)
wlogger.info(`Request: ${ip} ${method} ${url}`, dataToLog)
next()
} catch (err) {
+18 -2
View File
@@ -1,6 +1,4 @@
/*
This file will replace the original rate-limit.js file.
Sets the rate limits for the anonymous and paid tiers. Current rate limits:
- 10000 points in 60 seconds
- 500 points per call for anonymous tier (20 RPM)
@@ -258,6 +256,15 @@ class RateLimits {
// const rateLimitData = await _this.rateLimiter.consume(key, pointsToConsume)
// console.log(`rateLimitData: `, rateLimitData)
// Add data to logs for analytics.
const logData = {
ip: req.ip,
key,
pointsToConsume,
status: 'OK'
}
wlogger.info(logData)
res.locals.pointsToConsume = pointsToConsume // Feedback for tests.
// Signal that the user has not exceeded their rate limits.
@@ -274,6 +281,15 @@ class RateLimits {
// `rate limit debug info: ${JSON.stringify(debugInfo, null, 2)}`
// )
// Add data to logs for analytics.
const logData = {
ip: req.ip,
key,
pointsToConsume,
status: 429
}
wlogger.info(logData)
// Rate limited was triggered
res.status(429) // https://github.com/Bitcoin-com/rest.bitcoin.com/issues/330
return res.json({