fix(rule apply test): do not crash when the rule is not found
This commit is contained in:
parent
3ba5cb7858
commit
9576efb716
|
@ -274,6 +274,7 @@ schema("/rules/:id/test") ->
|
|||
responses => #{
|
||||
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
|
||||
412 => error_schema('NOT_MATCH', "SQL Not Match"),
|
||||
404 => error_schema('RULE_NOT_FOUND', "The rule could not be found"),
|
||||
200 => <<"Rule Applied">>
|
||||
}
|
||||
}
|
||||
|
@ -424,6 +425,8 @@ param_path_id() ->
|
|||
{400, #{code => 'BAD_REQUEST', message => err_msg(Reason)}};
|
||||
{error, nomatch} ->
|
||||
{412, #{code => 'NOT_MATCH', message => <<"SQL Not Match">>}};
|
||||
{error, rule_not_found} ->
|
||||
{404, #{code => 'RULE_NOT_FOUND', message => <<"The rule could not be found">>}};
|
||||
{error, Reason} ->
|
||||
{400, #{code => 'BAD_REQUEST', message => err_msg(Reason)}}
|
||||
end
|
||||
|
|
|
@ -26,12 +26,22 @@
|
|||
|
||||
apply_rule(
|
||||
RuleId,
|
||||
Parameters
|
||||
) ->
|
||||
case emqx_rule_engine:get_rule(RuleId) of
|
||||
{ok, Rule} ->
|
||||
do_apply_rule(Rule, Parameters);
|
||||
not_found ->
|
||||
{error, rule_not_found}
|
||||
end.
|
||||
|
||||
do_apply_rule(
|
||||
Rule,
|
||||
#{
|
||||
context := Context,
|
||||
stop_action_after_template_rendering := StopAfterRender
|
||||
}
|
||||
) ->
|
||||
{ok, Rule} = emqx_rule_engine:get_rule(RuleId),
|
||||
InTopic = get_in_topic(Context),
|
||||
EventTopics = maps:get(from, Rule, []),
|
||||
case lists:all(fun is_publish_topic/1, EventTopics) of
|
||||
|
|
Loading…
Reference in New Issue