Skip to content

Commit 7bfe2fd

Browse files
committed
Return 404 in AMQP management queue purge for non-existing queue
1 parent 4627e7a commit 7bfe2fd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

deps/rabbit/src/rabbit_amqp_management.erl

+3-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,9 @@ handle_http_req(<<"DELETE">>,
256256
[rabbit_misc:rs(QName)])
257257
end
258258
end)
259-
catch exit:#amqp_error{explanation = Explanation} ->
259+
catch exit:#amqp_error{name = not_found, explanation = Explanation} ->
260+
throw(<<"404">>, Explanation, []);
261+
exit:#amqp_error{explanation = Explanation} ->
260262
throw(<<"400">>, Explanation, [])
261263
end;
262264

deps/rabbitmq_amqp_client/test/management_SUITE.erl

+13
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ groups() ->
7575
unbind_bad_binding_path_segment,
7676
exclusive_queue,
7777
purge_stream,
78+
purge_non_existing_queue_should_return_not_found,
7879
pipeline,
7980
multiple_link_pairs,
8081
link_attach_order,
@@ -773,6 +774,18 @@ purge_stream(Config) ->
773774
{ok, #{}} = rabbitmq_amqp_client:delete_queue(LinkPair, QName),
774775
ok = cleanup(Init).
775776

777+
purge_non_existing_queue_should_return_not_found(Config) ->
778+
Init = {_, LinkPair} = init(Config),
779+
QName = atom_to_binary(?FUNCTION_NAME),
780+
781+
{error, Resp} = rabbitmq_amqp_client:purge_queue(LinkPair, QName),
782+
?assertMatch(#{subject := <<"404">>}, amqp10_msg:properties(Resp)),
783+
#'v1_0.amqp_value'{content = {utf8, Reason}} = amqp10_msg:body(Resp),
784+
?assertEqual(<<"no queue '", QName/binary, "' in vhost '/'">>,
785+
Reason),
786+
787+
ok = cleanup(Init).
788+
776789
queue_topology(Config) ->
777790
NodeNames = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
778791
Nodes = [N0, N1, N2] = lists:map(fun erlang:atom_to_binary/1, NodeNames),

0 commit comments

Comments
 (0)