Просмотр исходного кода

fix(api): client subscriptions formatter fun bad match

DDDHuang 4 лет назад
Родитель
Сommit
e07ecd5211
2 измененных файлов с 16 добавлено и 7 удалено
  1. 1 2
      apps/emqx_management/src/emqx_mgmt.erl
  2. 15 5
      apps/emqx_management/src/emqx_mgmt_api_clients.erl

+ 1 - 2
apps/emqx_management/src/emqx_mgmt.erl

@@ -276,8 +276,7 @@ list_client_subscriptions(ClientId) ->
             ({_Node, List}) ->
             ({_Node, List}) ->
                 erlang:is_list(List) andalso 0 < erlang:length(List)
                 erlang:is_list(List) andalso 0 < erlang:length(List)
         end,
         end,
-    Expected = lists:filter(Filter, Results),
-    case Expected of
+    case lists:filter(Filter, Results) of
         [] -> [];
         [] -> [];
         [Result | _] -> Result
         [Result | _] -> Result
     end.
     end.

+ 15 - 5
apps/emqx_management/src/emqx_mgmt_api_clients.erl

@@ -513,11 +513,21 @@ subscribe_batch(post, #{bindings := #{clientid := ClientID}, body := TopicInfos}
     subscribe_batch(#{clientid => ClientID, topics => Topics}).
     subscribe_batch(#{clientid => ClientID, topics => Topics}).
 
 
 subscriptions(get, #{bindings := #{clientid := ClientID}}) ->
 subscriptions(get, #{bindings := #{clientid := ClientID}}) ->
-    {Node, Subs0} = emqx_mgmt:list_client_subscriptions(ClientID),
-    Subs = lists:map(fun({Topic, SubOpts}) ->
-        #{node => Node, clientid => ClientID, topic => Topic, qos => maps:get(qos, SubOpts)}
-    end, Subs0),
-    {200, Subs}.
+    case emqx_mgmt:list_client_subscriptions(ClientID) of
+        [] ->
+            {200, []};
+        {Node, Subs} ->
+            Formatter =
+                fun({Topic, SubOpts}) ->
+                    #{
+                        node => Node,
+                        clientid => ClientID,
+                        topic => Topic,
+                        qos => maps:get(qos, SubOpts)
+                    }
+                end,
+        {200, lists:map(Formatter, Subs)}
+    end.
 
 
 set_keepalive(put, #{bindings := #{clientid := ClientID}, query_string := Query}) ->
 set_keepalive(put, #{bindings := #{clientid := ClientID}, query_string := Query}) ->
     case maps:find(<<"interval">>, Query) of
     case maps:find(<<"interval">>, Query) of