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

feat: allow specifying more helpful messages for unhealthy targets

Thales Macedo Garitezi 2 лет назад
Родитель
Сommit
c4fc0e767e

+ 2 - 0
apps/emqx_bridge/src/emqx_bridge_api.erl

@@ -1000,6 +1000,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(Reason)
     end.

+ 2 - 0
apps/emqx_resource/src/emqx_resource.erl

@@ -282,6 +282,8 @@ query(ResId, Request, Opts) ->
             case {QM, Error} of
                 {_, unhealthy_target} ->
                     ?RESOURCE_ERROR(unhealthy_target, "unhealthy target");
+                {_, {unhealthy_target, _Message}} ->
+                    ?RESOURCE_ERROR(unhealthy_target, "unhealthy target");
                 {simple_async, _} ->
                     %% TODO(5.1.1): pass Resource instead of ResId to simple APIs
                     %% so the buffer worker does not need to lookup the cache again

+ 1 - 0
apps/emqx_resource/src/emqx_resource_manager.erl

@@ -642,6 +642,7 @@ status_to_error(_) ->
     {error, undefined}.
 
 %% Compatibility
+external_error({error, {unhealthy_target, Message}}) -> Message;
 external_error({error, Reason}) -> Reason;
 external_error(Other) -> Other.