chore: improve the error message if the parameter invalid
This commit is contained in:
parent
3d7264c9ef
commit
f45298d14a
|
@ -206,14 +206,19 @@ cluster_query(Tab, QString, QSchema, MsFun, FmtFun, Options) ->
|
|||
false ->
|
||||
{error, page_limit_invalid};
|
||||
Meta ->
|
||||
{_CodCnt, NQString} = parse_qstring(QString, QSchema),
|
||||
Nodes = emqx:running_nodes(),
|
||||
ResultAcc = init_query_result(),
|
||||
QueryState = init_query_state(Tab, NQString, MsFun, Meta, Options),
|
||||
NResultAcc = do_cluster_query(
|
||||
Nodes, QueryState, ResultAcc
|
||||
),
|
||||
format_query_result(FmtFun, Meta, NResultAcc)
|
||||
try
|
||||
{_CodCnt, NQString} = parse_qstring(QString, QSchema),
|
||||
Nodes = emqx:running_nodes(),
|
||||
ResultAcc = init_query_result(),
|
||||
QueryState = init_query_state(Tab, NQString, MsFun, Meta, Options),
|
||||
NResultAcc = do_cluster_query(
|
||||
Nodes, QueryState, ResultAcc
|
||||
),
|
||||
format_query_result(FmtFun, Meta, NResultAcc)
|
||||
catch
|
||||
throw:{bad_value_type, {Key, ExpectedType, AcutalValue}} ->
|
||||
{error, invalid_query_string_param, {Key, ExpectedType, AcutalValue}}
|
||||
end
|
||||
end.
|
||||
|
||||
%% @private
|
||||
|
|
|
@ -699,6 +699,14 @@ list_clients(QString) ->
|
|||
case Result of
|
||||
{error, page_limit_invalid} ->
|
||||
{400, #{code => <<"INVALID_PARAMETER">>, message => <<"page_limit_invalid">>}};
|
||||
{error, invalid_query_string_param, {Key, ExpectedType, AcutalValue}} ->
|
||||
Message = list_to_binary(
|
||||
io_lib:format(
|
||||
"the ~s parameter expected type is ~s, but the got value is ~s",
|
||||
[Key, ExpectedType, emqx_utils_conv:str(AcutalValue)]
|
||||
)
|
||||
),
|
||||
{400, #{code => <<"INVALID_PARAMETER">>, message => Message}};
|
||||
{error, Node, {badrpc, R}} ->
|
||||
Message = list_to_binary(io_lib:format("bad rpc call ~p, Reason ~p", [Node, R])),
|
||||
{500, #{code => <<"NODE_DOWN">>, message => Message}};
|
||||
|
|
|
@ -167,6 +167,23 @@ t_clients(_) ->
|
|||
AfterKickoutResponse1 = emqx_mgmt_api_test_util:request_api(get, Client1Path),
|
||||
?assertEqual({error, {"HTTP/1.1", 404, "Not Found"}}, AfterKickoutResponse1).
|
||||
|
||||
t_clients_bad_value_type(_) ->
|
||||
%% get /clients
|
||||
AuthHeader = [emqx_common_test_http:default_auth_header()],
|
||||
ClientsPath = emqx_mgmt_api_test_util:api_path(["clients"]),
|
||||
QsString = cow_qs:qs([{<<"ip_address">>, <<"127.0.0.1:8080">>}]),
|
||||
{ok, 400, Resp} = emqx_mgmt_api_test_util:request_api(
|
||||
get, ClientsPath, QsString, AuthHeader, [], #{compatible_mode => true}
|
||||
),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"code">> := <<"INVALID_PARAMETER">>,
|
||||
<<"message">> :=
|
||||
<<"the ip_address parameter expected type is ip, but the got value is 127.0.0.1:8080">>
|
||||
},
|
||||
emqx_utils_json:decode(Resp, [return_maps])
|
||||
).
|
||||
|
||||
t_authz_cache(_) ->
|
||||
ClientId = <<"client_authz">>,
|
||||
|
||||
|
|
Loading…
Reference in New Issue