fix: deny creating metrics for empty topics (#5650)

* fix: deny null topic create metrics
This commit is contained in:
DDDHuang 2021-09-03 18:32:23 +08:00 committed by GitHub
parent 8f6931e5b0
commit f5bfa4cd43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -94,7 +94,7 @@ topic_metrics_api() ->
responses => #{ responses => #{
<<"200">> => schema(<<"Create topic metrics success">>), <<"200">> => schema(<<"Create topic metrics success">>),
<<"409">> => error_schema(<<"Topic metrics max limit">>, [?EXCEED_LIMIT]), <<"409">> => error_schema(<<"Topic metrics max limit">>, [?EXCEED_LIMIT]),
<<"400">> => error_schema(<<"Topic metrics already exist">>, [?BAD_REQUEST]) <<"400">> => error_schema(<<"Topic metrics already exist or bad topic">>, [?BAD_REQUEST])
} }
} }
}, },
@ -137,6 +137,8 @@ topic_metrics(put, #{body := #{<<"topic">> := Topic, <<"action">> := <<"reset">>
reset(Topic); reset(Topic);
topic_metrics(put, #{body := #{<<"action">> := <<"reset">>}}) -> topic_metrics(put, #{body := #{<<"action">> := <<"reset">>}}) ->
reset(); reset();
topic_metrics(post, #{body := #{<<"topic">> := <<>>}}) ->
{400, 'BAD_REQUEST', <<"Topic can not be empty">>};
topic_metrics(post, #{body := #{<<"topic">> := Topic}}) -> topic_metrics(post, #{body := #{<<"topic">> := Topic}}) ->
register(Topic). register(Topic).