fix(api): topic metrics check exist before create

This commit is contained in:
DDDHuang 2022-07-13 10:35:33 +08:00
parent 265d3200c2
commit 8f18bdff15
2 changed files with 11 additions and 6 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_modules, [
{description, "EMQX Modules"},
{vsn, "5.0.1"},
{vsn, "5.0.2"},
{modules, []},
{applications, [kernel, stdlib, emqx]},
{mod, {emqx_modules_app, []}},

View File

@ -296,11 +296,16 @@ topic_metrics(put, #{body := #{<<"action">> := <<"reset">>}}) ->
topic_metrics(post, #{body := #{<<"topic">> := <<>>}}) ->
{400, 'BAD_REQUEST', <<"Topic can not be empty">>};
topic_metrics(post, #{body := #{<<"topic">> := Topic}}) ->
case emqx_modules_conf:add_topic_metrics(Topic) of
{ok, Topic} ->
get_cluster_response([Topic]);
{error, Reason} ->
reason2httpresp(Reason)
case lists:member(Topic, emqx_modules_conf:topic_metrics()) of
false ->
case emqx_modules_conf:add_topic_metrics(Topic) of
{ok, Topic} ->
get_cluster_response([Topic]);
{error, Reason} ->
reason2httpresp(Reason)
end;
true ->
reason2httpresp(already_existed)
end.
operate_topic_metrics(get, #{bindings := #{topic := Topic}}) ->