fix(emqx_rule_engine): don't crash if we can't encode json
This commit is contained in:
parent
072d310507
commit
44eca1fa72
|
@ -423,13 +423,21 @@ param_path_id() ->
|
|||
%% Internal functions
|
||||
%%------------------------------------------------------------------------------
|
||||
|
||||
err_msg({RuleError, {_E, R, _S}}) when is_tuple(R) ->
|
||||
emqx_misc:readable_error_msg(emqx_json:encode([{RuleError, element(1, R)}]));
|
||||
err_msg({RuleError, {_E, R, _S}}) ->
|
||||
emqx_misc:readable_error_msg(emqx_json:encode([{RuleError, R}]));
|
||||
err_msg({RuleError, {_E, Reason, _S}}) ->
|
||||
emqx_misc:readable_error_msg(encode_nested_error(RuleError, Reason));
|
||||
err_msg(Msg) ->
|
||||
emqx_misc:readable_error_msg(Msg).
|
||||
|
||||
encode_nested_error(RuleError, Reason) when is_tuple(Reason) ->
|
||||
encode_nested_error(RuleError, element(1, Reason));
|
||||
encode_nested_error(RuleError, Reason) ->
|
||||
case emqx_json:safe_encode([{RuleError, Reason}]) of
|
||||
{ok, Json} ->
|
||||
Json;
|
||||
_ ->
|
||||
{RuleError, Reason}
|
||||
end.
|
||||
|
||||
format_rule_resp(Rules) when is_list(Rules) ->
|
||||
[format_rule_resp(R) || R <- Rules];
|
||||
format_rule_resp({Id, Rule}) ->
|
||||
|
|
Loading…
Reference in New Issue