@musicode/egg-rate-limiter
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -27,4 +27,3 @@ | ||
* } | ||
* options.error - 超过调用上限时的错误信息 | ||
* options.tidy - limit the records count, no greater than max [false] | ||
* options.onError - 超过调用上限时的回调 | ||
*/ | ||
@@ -35,3 +34,3 @@ module.exports = (options, app) => { | ||
routers, | ||
error, | ||
onError, | ||
} = options | ||
@@ -97,5 +96,10 @@ | ||
// 429 表示过多的请求 | ||
ctx.status = 429 | ||
ctx.body = error || `Rate limit exceeded, retry in ${ms(delta, { long: true })}.` | ||
if (onError) { | ||
onError(ctx) | ||
} | ||
else { | ||
// 429 表示过多的请求 | ||
ctx.status = 429 | ||
ctx.body = `Rate limit exceeded, retry in ${ms(delta, { long: true })}.` | ||
} | ||
@@ -102,0 +106,0 @@ } |
{ | ||
"name": "@musicode/egg-rate-limiter", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "eggPlugin": { |
14026
8
98