Skip to content

Commit 93946ee

Browse files
committed
Handle the rabbitmqqueue:declare
The rabbitmqqueue:declare is handled, and in case of known errors, the correct error code is sent back. Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent 58d835b commit 93946ee

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

deps/rabbit/src/rabbit_amqp_management.erl

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ handle_http_req(HttpMethod = <<"PUT">>,
126126
ok = prohibit_reserved_amq(QName),
127127
PermCache1 = check_resource_access(QName, configure, User, PermCache0),
128128
rabbit_core_metrics:queue_declared(QName),
129-
130129
{Q1, NumMsgs, NumConsumers, StatusCode, PermCache} =
131130
case rabbit_amqqueue:with(
132131
QName,
@@ -147,29 +146,40 @@ handle_http_req(HttpMethod = <<"PUT">>,
147146
Result;
148147
{error, not_found} ->
149148
PermCache2 = check_dead_letter_exchange(QName, QArgs, User, PermCache1),
150-
case rabbit_amqqueue:declare(
151-
QName, Durable, AutoDelete, QArgs, Owner, Username) of
152-
{new, Q} ->
149+
try rabbit_amqqueue:declare(
150+
QName, Durable, AutoDelete, QArgs, Owner, Username) of
151+
ARGS ->
152+
case ARGS of
153+
{new, Q} ->
153154
rabbit_core_metrics:queue_created(QName),
154155
{Q, 0, 0, <<"201">>, PermCache2};
155-
{owner_died, Q} ->
156+
{owner_died, Q} ->
156157
%% Presumably our own days are numbered since the
157158
%% connection has died. Pretend the queue exists though,
158159
%% just so nothing fails.
159160
{Q, 0, 0, <<"201">>, PermCache2};
160-
{absent, Q, Reason} ->
161+
{absent, Q, Reason} ->
161162
absent(Q, Reason);
162-
{existing, _Q} ->
163+
{existing, _Q} ->
163164
%% Must have been created in the meantime. Loop around again.
164165
handle_http_req(HttpMethod, PathSegments, Query, ReqPayload,
165-
Vhost, User, ConnPid, {PermCache2, TopicPermCache});
166-
{error, queue_limit_exceeded, Reason, ReasonArgs} ->
166+
Vhost, User, ConnPid, {PermCache2, TopicPermCache});
167+
{error, queue_limit_exceeded, Reason, ReasonArgs} ->
167168
throw(<<"403">>,
168-
Reason,
169-
ReasonArgs);
170-
{protocol_error, _ErrorType, Reason, ReasonArgs} ->
171-
throw(<<"400">>, Reason, ReasonArgs)
169+
Reason,
170+
ReasonArgs);
171+
{protocol_error, _ErrorType, Reason, ReasonArgs} ->
172+
throw(<<"400">>, Reason, ReasonArgs);
173+
{precondition_failed, Reason, ReasonArgs} ->
174+
throw(<<"409">>, Reason, ReasonArgs)
175+
end
176+
catch exit:#amqp_error{name = precondition_failed,
177+
explanation = Expl} ->
178+
throw(<<"409">>, Expl, []);
179+
exit:#amqp_error{explanation = Expl} ->
180+
throw(<<"400">>, Expl, [])
172181
end;
182+
173183
{error, {absent, Q, Reason}} ->
174184
absent(Q, Reason)
175185
end,

0 commit comments

Comments
 (0)