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

fix(bridge_v2 operations): better error message

Kjell Winblad 2 лет назад
Родитель
Сommit
d14d0fbcb1

+ 1 - 3
apps/emqx_bridge/src/emqx_bridge_api.erl

@@ -1078,10 +1078,8 @@ call_operation(NodeOrAll, OperFunc, Args = [_Nodes, BridgeType, BridgeName]) ->
             ?NOT_FOUND(<<"Node not found: ", (atom_to_binary(Node))/binary>>);
         {error, {unhealthy_target, Message}} ->
             ?BAD_REQUEST(Message);
-        {error, Reason} when not is_tuple(Reason); element(1, Reason) =/= 'exit' ->
-            ?BAD_REQUEST(redact(Reason));
         {error, Reason} ->
-            ?BAD_REQUEST(Reason)
+            ?BAD_REQUEST(redact(Reason))
     end.
 
 maybe_try_restart(all, start_bridges_to_all_nodes, Args) ->

+ 7 - 2
apps/emqx_bridge/src/emqx_bridge_v2.erl

@@ -490,8 +490,13 @@ connector_operation_helper_with_conf(
                     ok;
                 {error, Reason} ->
                     {error, Reason};
-                NonConnectedStatus ->
-                    {error, NonConnectedStatus}
+                #{status := Status, error := Reason} ->
+                    Msg = io_lib:format(
+                        "Connector started but bridge (~s:~s) is not connected. "
+                        "Bridge Status: ~p, Error: ~p",
+                        [bin(BridgeV2Type), bin(Name), Status, Reason]
+                    ),
+                    {error, iolist_to_binary(Msg)}
             end
     end.
 

+ 1 - 5
apps/emqx_bridge/src/emqx_bridge_v2_api.erl

@@ -606,12 +606,8 @@ call_operation(NodeOrAll, OperFunc, Args = [_Nodes, BridgeType, BridgeName]) ->
             ?SERVICE_UNAVAILABLE(<<"Bridge not found on remote node: ", BridgeId/binary>>);
         {error, {node_not_found, Node}} ->
             ?NOT_FOUND(<<"Node not found: ", (atom_to_binary(Node))/binary>>);
-        {error, {unhealthy_target, Message}} ->
-            ?BAD_REQUEST(Message);
-        {error, Reason} when not is_tuple(Reason); element(1, Reason) =/= 'exit' ->
-            ?BAD_REQUEST(redact(Reason));
         {error, Reason} ->
-            ?BAD_REQUEST(Reason)
+            ?BAD_REQUEST(redact(Reason))
     end.
 
 do_bpapi_call(all, Call, Args) ->