Merge pull request #11995 from thalesmg/fix-action-api-bad-name-r53-20231121
fix(actions_api): don't crash on validation errors
This commit is contained in:
commit
01895fd660
|
@ -791,6 +791,8 @@ do_create_or_update_bridge(BridgeType, BridgeName, Conf, HttpStatusCode) ->
|
|||
PreOrPostConfigUpdate =:= pre_config_update;
|
||||
PreOrPostConfigUpdate =:= post_config_update
|
||||
->
|
||||
?BAD_REQUEST(map_to_json(redact(Reason)));
|
||||
{error, Reason} when is_map(Reason) ->
|
||||
?BAD_REQUEST(map_to_json(redact(Reason)))
|
||||
end.
|
||||
|
||||
|
|
|
@ -1021,6 +1021,28 @@ t_action_types(Config) ->
|
|||
?assert(lists:all(fun is_binary/1, Types), #{types => Types}),
|
||||
ok.
|
||||
|
||||
t_bad_name(Config) ->
|
||||
Name = <<"_bad_name">>,
|
||||
Res = request_json(
|
||||
post,
|
||||
uri([?ROOT]),
|
||||
?KAFKA_BRIDGE(Name),
|
||||
Config
|
||||
),
|
||||
?assertMatch({ok, 400, #{<<"message">> := _}}, Res),
|
||||
{ok, 400, #{<<"message">> := Msg0}} = Res,
|
||||
Msg = emqx_utils_json:decode(Msg0, [return_maps]),
|
||||
?assertMatch(
|
||||
#{
|
||||
<<"got">> := [<<"_bad_name">>],
|
||||
<<"kind">> := <<"validation_error">>,
|
||||
<<"path">> := <<"actions.kafka_producer">>,
|
||||
<<"reason">> := <<"invalid_map_key">>
|
||||
},
|
||||
Msg
|
||||
),
|
||||
ok.
|
||||
|
||||
%%% helpers
|
||||
listen_on_random_port() ->
|
||||
SockOpts = [binary, {active, false}, {packet, raw}, {reuseaddr, true}, {backlog, 1000}],
|
||||
|
|
Loading…
Reference in New Issue