Przeglądaj źródła

fix(mgmt): return null instead of "undefined" string

JianBo He 3 lat temu
rodzic
commit
1867b86bad

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

@@ -862,10 +862,12 @@ format_channel_info({_, ClientInfo0, ClientStats}) ->
         ],
         ],
     TimesKeys = [created_at, connected_at, disconnected_at],
     TimesKeys = [created_at, connected_at, disconnected_at],
     %% format timestamp to rfc3339
     %% format timestamp to rfc3339
-    lists:foldl(
-        fun result_format_time_fun/2,
-        maps:without(RemoveList, ClientInfoMap),
-        TimesKeys
+    result_format_undefined_to_null(
+        lists:foldl(
+            fun result_format_time_fun/2,
+            maps:without(RemoveList, ClientInfoMap),
+            TimesKeys
+        )
     ).
     ).
 
 
 %% format func helpers
 %% format func helpers
@@ -884,6 +886,15 @@ result_format_time_fun(Key, NClientInfoMap) ->
             NClientInfoMap
             NClientInfoMap
     end.
     end.
 
 
+result_format_undefined_to_null(Map) ->
+    maps:map(
+        fun
+            (_, undefined) -> null;
+            (_, V) -> V
+        end,
+        Map
+    ).
+
 -spec peername_dispart(emqx_types:peername()) -> {binary(), inet:port_number()}.
 -spec peername_dispart(emqx_types:peername()) -> {binary(), inet:port_number()}.
 peername_dispart({Addr, Port}) ->
 peername_dispart({Addr, Port}) ->
     AddrBinary = list_to_binary(inet:ntoa(Addr)),
     AddrBinary = list_to_binary(inet:ntoa(Addr)),