Browse Source

Merge pull request #7491 from HJianBo/fix-cm-call

fix(exproto): keep conn_mod attribute in ConnInfo
JianBo He 3 years atrás
parent
commit
e63f288ea7

+ 5 - 1
apps/emqx_gateway/src/emqx_gateway_api_clients.erl

@@ -177,6 +177,8 @@ subscriptions(get, #{
     ClientId = emqx_mgmt_util:urldecode(ClientId0),
     with_gateway(Name0, fun(GwName, _) ->
         case emqx_gateway_http:list_client_subscriptions(GwName, ClientId) of
+            {error, not_found} ->
+                return_http_error(404, "client process not found");
             {error, Reason} ->
                 return_http_error(500, Reason);
             {ok, Subs} ->
@@ -202,8 +204,10 @@ subscriptions(post, #{
                         GwName, ClientId, Topic, SubOpts
                     )
                 of
+                    {error, not_found} ->
+                        return_http_error(404, "client process not found");
                     {error, Reason} ->
-                        return_http_error(404, Reason);
+                        return_http_error(500, Reason);
                     {ok, {NTopic, NSubOpts}} ->
                         {201, maps:merge(NSubOpts, #{topic => NTopic})}
                 end

+ 4 - 4
apps/emqx_gateway/src/emqx_gateway_cm.erl

@@ -694,17 +694,17 @@ call(GwName, ClientId, Req, Timeout) ->
 
 do_call(GwName, ClientId, ChanPid, Req) ->
     case do_get_chann_conn_mod(GwName, ClientId, ChanPid) of
-        undefined -> throw(noproc);
+        undefined -> undefined;
         ConnMod -> ConnMod:call(ChanPid, Req)
     end.
 
 do_call(GwName, ClientId, ChanPid, Req, Timeout) ->
     case do_get_chann_conn_mod(GwName, ClientId, ChanPid) of
-        undefined -> throw(noproc);
+        undefined -> undefined;
         ConnMod -> ConnMod:call(ChanPid, Req, Timeout)
     end.
 
--spec cast(gateway_name(), emqx_types:clientid(), term()) -> ok.
+-spec cast(gateway_name(), emqx_types:clientid(), term()) -> undefined | ok.
 cast(GwName, ClientId, Req) ->
     with_channel(
         GwName,
@@ -719,7 +719,7 @@ cast(GwName, ClientId, Req) ->
 
 do_cast(GwName, ClientId, ChanPid, Req) ->
     case do_get_chann_conn_mod(GwName, ClientId, ChanPid) of
-        undefined -> throw(noproc);
+        undefined -> undefined;
         ConnMod -> ConnMod:cast(ChanPid, Req)
     end.
 

+ 0 - 1
apps/emqx_gateway/src/exproto/emqx_exproto_channel.erl

@@ -722,7 +722,6 @@ default_conninfo(ConnInfo) ->
         clean_start => true,
         clientid => undefined,
         username => undefined,
-        conn_mod => undefined,
         conn_props => #{},
         connected => true,
         proto_name => <<"exproto">>,