@@ -126,7 +126,6 @@ handle_http_req(HttpMethod = <<"PUT">>,
126
126
ok = prohibit_reserved_amq (QName ),
127
127
PermCache1 = check_resource_access (QName , configure , User , PermCache0 ),
128
128
rabbit_core_metrics :queue_declared (QName ),
129
-
130
129
{Q1 , NumMsgs , NumConsumers , StatusCode , PermCache } =
131
130
case rabbit_amqqueue :with (
132
131
QName ,
@@ -147,29 +146,40 @@ handle_http_req(HttpMethod = <<"PUT">>,
147
146
Result ;
148
147
{error , not_found } ->
149
148
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 } ->
153
154
rabbit_core_metrics :queue_created (QName ),
154
155
{Q , 0 , 0 , <<" 201" >>, PermCache2 };
155
- {owner_died , Q } ->
156
+ {owner_died , Q } ->
156
157
% % Presumably our own days are numbered since the
157
158
% % connection has died. Pretend the queue exists though,
158
159
% % just so nothing fails.
159
160
{Q , 0 , 0 , <<" 201" >>, PermCache2 };
160
- {absent , Q , Reason } ->
161
+ {absent , Q , Reason } ->
161
162
absent (Q , Reason );
162
- {existing , _Q } ->
163
+ {existing , _Q } ->
163
164
% % Must have been created in the meantime. Loop around again.
164
165
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 } ->
167
168
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 , [])
172
181
end ;
182
+
173
183
{error , {absent , Q , Reason }} ->
174
184
absent (Q , Reason )
175
185
end ,
0 commit comments