fix(bridge v1 api): return correct http response code when incompatible

This commit is contained in:
Thales Macedo Garitezi 2024-06-19 17:00:29 -03:00
parent b38e7066a5
commit 89bd69eb50
1 changed files with 13 additions and 2 deletions

View File

@ -501,7 +501,18 @@ schema("/bridges_probe") ->
end. end.
'/bridges/:id'(get, #{bindings := #{id := Id}}) -> '/bridges/:id'(get, #{bindings := #{id := Id}}) ->
?TRY_PARSE_ID(Id, lookup_from_all_nodes(BridgeType, BridgeName, 200)); ?TRY_PARSE_ID(
Id,
begin
CompatErrorMsg = non_compat_bridge_msg(),
case lookup_from_all_nodes(BridgeType, BridgeName, 200) of
{400, #{code := 'BAD_REQUEST', message := CompatErrorMsg}} ->
?BRIDGE_NOT_FOUND(BridgeType, BridgeName);
Res ->
Res
end
end
);
'/bridges/:id'(put, #{bindings := #{id := Id}, body := Conf0}) -> '/bridges/:id'(put, #{bindings := #{id := Id}, body := Conf0}) ->
Conf1 = filter_out_request_body(Conf0), Conf1 = filter_out_request_body(Conf0),
?TRY_PARSE_ID( ?TRY_PARSE_ID(
@ -634,7 +645,7 @@ lookup_from_all_nodes(BridgeType, BridgeName, SuccCode) ->
{ok, [{error, not_found} | _]} -> {ok, [{error, not_found} | _]} ->
?BRIDGE_NOT_FOUND(BridgeType, BridgeName); ?BRIDGE_NOT_FOUND(BridgeType, BridgeName);
{ok, [{error, not_bridge_v1_compatible} | _]} -> {ok, [{error, not_bridge_v1_compatible} | _]} ->
?NOT_FOUND(non_compat_bridge_msg()); ?BAD_REQUEST(non_compat_bridge_msg());
{error, Reason} -> {error, Reason} ->
?INTERNAL_ERROR(Reason) ?INTERNAL_ERROR(Reason)
end. end.