Merge pull request #9678 from kjellwinblad/kjell/fix/jira/EMQX-8648

fix: no feedback when deleting non-existing configuration
This commit is contained in:
Kjell Winblad 2023-01-09 13:52:40 +01:00 committed by GitHub
commit 692c1f0d1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 12 deletions

View File

@ -328,6 +328,7 @@ schema("/bridges/:id") ->
responses => #{
204 => <<"Bridge deleted">>,
400 => error_schema(['INVALID_ID'], "Update bridge failed"),
404 => error_schema('NOT_FOUND', "Bridge not found"),
403 => error_schema('FORBIDDEN_REQUEST', "Forbidden operation"),
503 => error_schema('SERVICE_UNAVAILABLE', "Service unavailable")
}
@ -433,19 +434,24 @@ schema("/nodes/:node/bridges/:id/operation/:operation") ->
end,
?TRY_PARSE_ID(
Id,
case emqx_bridge:check_deps_and_remove(BridgeType, BridgeName, AlsoDeleteActs) of
case emqx_bridge:lookup(BridgeType, BridgeName) of
{ok, _} ->
204;
{error, {rules_deps_on_this_bridge, RuleIds}} ->
{403,
error_msg(
'FORBIDDEN_REQUEST',
{<<"There're some rules dependent on this bridge">>, RuleIds}
)};
{error, timeout} ->
{503, error_msg('SERVICE_UNAVAILABLE', <<"request timeout">>)};
{error, Reason} ->
{500, error_msg('INTERNAL_ERROR', Reason)}
case emqx_bridge:check_deps_and_remove(BridgeType, BridgeName, AlsoDeleteActs) of
{ok, _} ->
204;
{error, {rules_deps_on_this_bridge, RuleIds}} ->
{403,
error_msg(
'FORBIDDEN_REQUEST',
{<<"There're some rules dependent on this bridge">>, RuleIds}
)};
{error, timeout} ->
{503, error_msg('SERVICE_UNAVAILABLE', <<"request timeout">>)};
{error, Reason} ->
{500, error_msg('INTERNAL_ERROR', Reason)}
end;
{error, not_found} ->
{404, error_msg('NOT_FOUND', <<"Bridge not found">>)}
end
).

View File

@ -303,6 +303,15 @@ t_http_crud_apis(Config) ->
},
jsx:decode(ErrMsg2)
),
%% Deleting a non-existing bridge should result in an error
{ok, 404, ErrMsg3} = request(delete, uri(["bridges", BridgeID]), []),
?assertMatch(
#{
<<"code">> := _,
<<"message">> := <<"Bridge not found">>
},
jsx:decode(ErrMsg3)
),
ok.
t_http_bridges_local_topic(Config) ->

View File

@ -0,0 +1 @@
When deleting a non-existing bridge the server gave a success response. This has been fixed so that the server instead gives an error response when the user attempts to delete a non-existing bridge.

View File

@ -0,0 +1 @@
修复了当通过 API 删除一个不存在的桥接时,服务器会返回操作成功的问题,现在将会返回操作失败的信息。