fix(limiter): fix schema parse error

This commit is contained in:
firest 2022-04-28 18:26:22 +08:00
parent 53df222c48
commit 60c2427874
1 changed files with 14 additions and 6 deletions

View File

@ -208,12 +208,19 @@ to_rate(Str, CanInfinity, CanZero) ->
to_capacity(QuotaStr, Str, CanZero, Fun); to_capacity(QuotaStr, Str, CanZero, Fun);
[QuotaStr, Interval] -> [QuotaStr, Interval] ->
Fun = fun(Quota) -> Fun = fun(Quota) ->
try
case emqx_schema:to_duration_ms(Interval) of case emqx_schema:to_duration_ms(Interval) of
{ok, Ms} when Ms > 0 -> {ok, Ms} when Ms > 0 ->
{ok, Quota * minimum_period() / Ms}; {ok, Quota * minimum_period() / Ms};
{ok, 0} when CanZero ->
{ok, 0};
_ -> _ ->
{error, Str} {error, Str}
end end
catch
_:_ ->
{error, Str}
end
end, end,
to_capacity(QuotaStr, Str, CanZero, Fun); to_capacity(QuotaStr, Str, CanZero, Fun);
_ -> _ ->
@ -226,8 +233,9 @@ to_capacity(QuotaStr, Str, CanZero, Fun) ->
{error, _Error} -> {error, Str} {error, _Error} -> {error, Str}
end. end.
check_capacity(_Str, 0, true, _Cont) -> check_capacity(_Str, 0, true, Cont) ->
{ok, 0}; %% must check the interval part or maybe will get incorrect config, e.g. "0/0sHello"
Cont(0);
check_capacity(Str, 0, false, _Cont) -> check_capacity(Str, 0, false, _Cont) ->
{error, Str}; {error, Str};
check_capacity(_Str, Quota, _CanZero, Cont) -> check_capacity(_Str, Quota, _CanZero, Cont) ->