chore: improve error message

This commit is contained in:
JianBo He 2022-04-22 17:08:18 +08:00
parent 9635361a89
commit 239f159306
2 changed files with 6 additions and 16 deletions

View File

@ -309,6 +309,10 @@ do_register(Topic, Speeds) ->
{error, already_existed}; {error, already_existed};
false -> false ->
case {number_of_registered_topics() < ?MAX_TOPICS, emqx_topic:wildcard(Topic)} of case {number_of_registered_topics() < ?MAX_TOPICS, emqx_topic:wildcard(Topic)} of
{_, true} ->
{error, bad_topic};
{false, _} ->
{error, quota_exceeded};
{true, false} -> {true, false} ->
CreateTime = emqx_rule_funcs:now_rfc3339(), CreateTime = emqx_rule_funcs:now_rfc3339(),
CRef = counters:new(counters_size(), [write_concurrency]), CRef = counters:new(counters_size(), [write_concurrency]),
@ -325,13 +329,7 @@ do_register(Topic, Speeds) ->
Speeds, Speeds,
?TOPIC_METRICS ?TOPIC_METRICS
), ),
{ok, NSpeeds}; {ok, NSpeeds}
{true, true} ->
{error, bad_topic};
{false, false} ->
{error, quota_exceeded};
{false, true} ->
{error, {quota_exceeded, bad_topic}}
end end
end. end.

View File

@ -572,16 +572,8 @@ reason2httpresp(quota_exceeded) ->
), ),
{409, #{code => ?EXCEED_LIMIT, message => Msg}}; {409, #{code => ?EXCEED_LIMIT, message => Msg}};
reason2httpresp(bad_topic) -> reason2httpresp(bad_topic) ->
Msg = <<"Bad Topic, topic cannot have wildcard">>, Msg = <<"Wildcard topic is not supported">>,
{400, #{code => ?BAD_TOPIC, message => Msg}}; {400, #{code => ?BAD_TOPIC, message => Msg}};
reason2httpresp({quota_exceeded, bad_topic}) ->
Msg = list_to_binary(
io_lib:format(
"Max topic metrics count is ~p, and topic cannot have wildcard",
[emqx_topic_metrics:max_limit()]
)
),
{400, #{code => ?BAD_REQUEST, message => Msg}};
reason2httpresp(already_existed) -> reason2httpresp(already_existed) ->
Msg = <<"Topic already registered">>, Msg = <<"Topic already registered">>,
{400, #{code => ?BAD_TOPIC, message => Msg}}; {400, #{code => ?BAD_TOPIC, message => Msg}};