fix(api): respond 404 on the deletion of nonexistent rule
This commit is contained in:
parent
c4f2dba9c5
commit
49e9ace1c1
|
@ -2,7 +2,7 @@
|
|||
{application, emqx_rule_engine, [
|
||||
{description, "EMQX Rule Engine"},
|
||||
% strict semver, bump manually!
|
||||
{vsn, "5.0.15"},
|
||||
{vsn, "5.0.16"},
|
||||
{modules, []},
|
||||
{registered, [emqx_rule_engine_sup, emqx_rule_engine]},
|
||||
{applications, [kernel, stdlib, rulesql, getopt, emqx_ctl]},
|
||||
|
|
|
@ -407,6 +407,8 @@ param_path_id() ->
|
|||
{400, #{code => 'BAD_REQUEST', message => ?ERR_BADARGS(Reason)}}
|
||||
end;
|
||||
'/rules/:id'(delete, #{bindings := #{id := Id}}) ->
|
||||
case emqx_rule_engine:get_rule(Id) of
|
||||
{ok, _Rule} ->
|
||||
ConfPath = emqx_rule_engine:config_key_path() ++ [Id],
|
||||
case emqx_conf:remove(ConfPath, #{override_to => cluster}) of
|
||||
{ok, _} ->
|
||||
|
@ -418,6 +420,9 @@ param_path_id() ->
|
|||
reason => Reason
|
||||
}),
|
||||
{500, #{code => 'INTERNAL_ERROR', message => ?ERR_BADARGS(Reason)}}
|
||||
end;
|
||||
not_found ->
|
||||
{404, #{code => 'NOT_FOUND', message => <<"Rule Id Not Found">>}}
|
||||
end.
|
||||
|
||||
'/rules/:id/metrics'(get, #{bindings := #{id := Id}}) ->
|
||||
|
|
|
@ -120,7 +120,14 @@ t_crud_rule_api(_Config) ->
|
|||
)
|
||||
),
|
||||
|
||||
%ct:pal("Show After Deleted: ~p", [NotFound]),
|
||||
?assertMatch(
|
||||
{404, #{code := 'NOT_FOUND'}},
|
||||
emqx_rule_engine_api:'/rules/:id'(
|
||||
delete,
|
||||
#{bindings => #{id => RuleId}}
|
||||
)
|
||||
),
|
||||
|
||||
?assertMatch(
|
||||
{404, #{code := _, message := _Message}},
|
||||
emqx_rule_engine_api:'/rules/:id'(get, #{bindings => #{id => RuleId}})
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
In Rule API, reapond with 404 HTTP error code when trying to delete a rule that does not exist.
|
Loading…
Reference in New Issue