From 33e01409deec44e18d4c47012b88884493bd3235 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 30 Sep 2009 07:13:46 +0100 Subject: fix handling of precondition_failed --- src/rabbit_channel.erl | 18 ++++++------------ src/rabbit_reader.erl | 27 ++++++++++++++++++--------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index a1fa1066..c1a5de1f 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -260,12 +260,6 @@ expand_routing_key_shortcut(<<>>, <<>>, expand_routing_key_shortcut(_QueueNameBin, RoutingKey, _State) -> RoutingKey. -die_precondition_failed(Fmt, Params) -> - %% FIXME: 406 should be replaced with precondition_failed when we - %% move to AMQP spec >=8.1 - rabbit_misc:protocol_error({false, 406, <<"PRECONDITION_FAILED">>}, - Fmt, Params). - %% check that an exchange/queue name does not contain the reserved %% "amq." prefix. %% @@ -610,8 +604,8 @@ handle_method(#'exchange.delete'{exchange = ExchangeNameBin, {error, not_found} -> rabbit_misc:not_found(ExchangeName); {error, in_use} -> - die_precondition_failed( - "~s in use", [rabbit_misc:rs(ExchangeName)]); + rabbit_misc:protocol_error( + precondition_failed, "~s in use", [rabbit_misc:rs(ExchangeName)]); ok -> return_ok(State, NoWait, #'exchange.delete_ok'{}) end; @@ -685,11 +679,11 @@ handle_method(#'queue.delete'{queue = QueueNameBin, QueueName, fun (Q) -> rabbit_amqqueue:delete(Q, IfUnused, IfEmpty) end) of {error, in_use} -> - die_precondition_failed( - "~s in use", [rabbit_misc:rs(QueueName)]); + rabbit_misc:protocol_error( + precondition_failed, "~s in use", [rabbit_misc:rs(QueueName)]); {error, not_empty} -> - die_precondition_failed( - "~s not empty", [rabbit_misc:rs(QueueName)]); + rabbit_misc:protocol_error( + precondition_failed, "~s not empty", [rabbit_misc:rs(QueueName)]); {ok, PurgedMessageCount} -> return_ok(State, NoWait, #'queue.delete_ok'{ diff --git a/src/rabbit_reader.erl b/src/rabbit_reader.erl index 5cc98992..057da787 100644 --- a/src/rabbit_reader.erl +++ b/src/rabbit_reader.erl @@ -751,18 +751,27 @@ map_exception(Channel, Reason) -> end, {ShouldClose, CloseChannel, CloseMethod}. -lookup_amqp_exception( - #amqp_error{name = Name, explanation = Expl, method = Method}) -> +%% FIXME: this clause can go when we move to AMQP spec >=8.1 +lookup_amqp_exception(#amqp_error{name = precondition_failed, + explanation = Expl, + method = Method}) -> + ExplBin = amqp_exception_explanation(<<"PRECONDITION_FAILED">>, Expl), + {false, 406, ExplBin, Method}; +lookup_amqp_exception(#amqp_error{name = Name, + explanation = Expl, + method = Method}) -> {ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(Name), - ExplBin = list_to_binary(Expl), - CompleteTextBin = <>, - SafeTextBin = if size(CompleteTextBin) > 255 -> - <>; - true -> CompleteTextBin - end, - {ShouldClose, Code, SafeTextBin, Method}; + ExplBin = amqp_exception_explanation(Text, Expl), + {ShouldClose, Code, ExplBin, Method}; lookup_amqp_exception(Other) -> rabbit_log:warning("Non-AMQP exit reason '~p'~n", [Other]), {ShouldClose, Code, Text} = rabbit_framing:lookup_amqp_exception(internal_error), {ShouldClose, Code, Text, none}. + +amqp_exception_explanation(Text, Expl) -> + ExplBin = list_to_binary(Expl), + CompleteTextBin = <>, + if size(CompleteTextBin) > 255 -> <>; + true -> CompleteTextBin + end. -- cgit v1.2.1