feat: allow specifying more helpful messages for unhealthy targets

This commit is contained in:
Thales Macedo Garitezi 2023-06-23 16:26:20 -03:00
parent 30d78aaac2
commit c4fc0e767e
3 changed files with 5 additions and 0 deletions

View File

@ -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.

View File

@ -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

View File

@ -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.