diff options
| author | Alvaro Videla <videlalvaro@gmail.com> | 2013-12-19 23:19:08 +0100 |
|---|---|---|
| committer | Alvaro Videla <videlalvaro@gmail.com> | 2013-12-19 23:19:08 +0100 |
| commit | dd6f5a53b014dbf6b1fb1090c55827f7cdc9eeac (patch) | |
| tree | 565ea0d1355e56eaca26238bf97e6c4da35e862c | |
| parent | 2c685640a362ed8e06e728ea2c16b813086d1aa0 (diff) | |
| download | rabbitmq-server-git-dd6f5a53b014dbf6b1fb1090c55827f7cdc9eeac.tar.gz | |
refactors intercept_method error handling
| -rw-r--r-- | src/rabbit_channel.erl | 34 | ||||
| -rw-r--r-- | src/rabbit_channel_interceptor.erl | 16 |
2 files changed, 23 insertions, 27 deletions
diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index ebac2e6abb..ccd7cb040c 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -274,27 +274,19 @@ handle_cast({method, Method, Content, Flow}, end, %% handle MRDQ before calling handle method M = handle_expand_shortcuts(Method, State), - try rabbit_channel_interceptor:intercept_method(M) of - {ok, Method2} -> - try handle_method(Method2, Content, State) of - {reply, Reply, NewState} -> - ok = send(Reply, NewState), - noreply(NewState); - {noreply, NewState} -> - noreply(NewState); - stop -> - {stop, normal, State} - catch - exit:Reason = #amqp_error{} -> - handle_method_exception(Reason, Method2, State); - _:Reason -> - {stop, {Reason, erlang:get_stacktrace()}, State} - end; - {error, Reason} -> - rabbit_misc:protocol_error(internal_error, Reason, []) + try handle_method(rabbit_channel_interceptor:intercept_method(M), + Content, State) of + {reply, Reply, NewState} -> + ok = send(Reply, NewState), + noreply(NewState); + {noreply, NewState} -> + noreply(NewState); + stop -> + {stop, normal, State} catch exit:Reason = #amqp_error{} -> - handle_method_exception(Reason, Method, State); + MethodName = rabbit_misc:method_record_type(Method), + handle_exception(Reason#amqp_error{method = MethodName}, State); _:Reason -> {stop, {Reason, erlang:get_stacktrace()}, State} end; @@ -438,10 +430,6 @@ send(_Command, #ch{state = closing}) -> send(Command, #ch{writer_pid = WriterPid}) -> ok = rabbit_writer:send_command(WriterPid, Command). -handle_method_exception(Reason, Method, State) -> - MethodName = rabbit_misc:method_record_type(Method), - handle_exception(Reason#amqp_error{method = MethodName}, State). - handle_exception(Reason, State = #ch{protocol = Protocol, channel = Channel, writer_pid = WriterPid, diff --git a/src/rabbit_channel_interceptor.erl b/src/rabbit_channel_interceptor.erl index 48b24082d5..48cd930ad3 100644 --- a/src/rabbit_channel_interceptor.erl +++ b/src/rabbit_channel_interceptor.erl @@ -54,12 +54,20 @@ intercept_method(M) -> intercept_method(M, select(M)). intercept_method(M, []) -> - {ok, M}; + M; intercept_method(M, [I]) -> - I:intercept(M); + case I:intercept(M) of + {ok, M2} -> + M2; + {error, Reason} -> + rabbit_misc:protocol_error(internal_error, + "Interceptor: ~p failed with reason: ~p", + [I, Reason]) + end; intercept_method(M, Is) -> - {error, rabbit_misc:format("More than one interceptor for method: ~p - ~p", - [rabbit_misc:method_record_type(M)], Is)}. + rabbit_misc:protocol_error(internal_error, + "More than one interceptor for method: ~p -- ~p", + [rabbit_misc:method_record_type(M), Is]). %% select the interceptors that apply to intercept_method(). select(Method) -> |
