summaryrefslogtreecommitdiff
path: root/lib/erl
diff options
context:
space:
mode:
authorАндрей Веселов <github.coffee@hotmail.com>2015-08-26 17:52:19 +0300
committerNobuaki Sukegawa <nsuke@apache.org>2015-11-27 00:08:27 +0900
commit547909933c25cbf0b8d2c91958dbd2972320513a (patch)
treec15d3b68b0ebe584a5fd2f69489d7e28eb794c68 /lib/erl
parente58ed1ad390dc15965acb2b898d60cf88364378b (diff)
downloadthrift-547909933c25cbf0b8d2c91958dbd2972320513a.tar.gz
THRIFT-3087 Pass on errors like "connection closed"
Client: Erlang Patch: Андрей Веселов and Nobuaki Sukegawa This closes #599
Diffstat (limited to 'lib/erl')
-rw-r--r--lib/erl/src/thrift_client.erl26
1 files changed, 15 insertions, 11 deletions
diff --git a/lib/erl/src/thrift_client.erl b/lib/erl/src/thrift_client.erl
index 7bf50a5c2..1a9cb50a4 100644
--- a/lib/erl/src/thrift_client.erl
+++ b/lib/erl/src/thrift_client.erl
@@ -63,7 +63,7 @@ close(#tclient{protocol=Protocol}) ->
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
--spec send_function_call(#tclient{}, atom(), list()) -> {sync | async | {error, any()}, #tclient{}}.
+-spec send_function_call(#tclient{}, atom(), list()) -> {ok | {error, any()}, #tclient{}}.
send_function_call(Client = #tclient{service = Service}, Function, Args) ->
{Params, Reply} = try
{Service:function_info(Function, params_type), Service:function_info(Function, reply_type)}
@@ -82,17 +82,21 @@ send_function_call(Client = #tclient{service = Service}, Function, Args) ->
end.
-spec write_message(#tclient{}, atom(), list(), {struct, list()}, integer()) ->
- {ok, #tclient{}}.
+ {ok | {error, any()}, #tclient{}}.
write_message(Client = #tclient{protocol = P0, seqid = Seq}, Function, Args, Params, MsgType) ->
- {P1, ok} = thrift_protocol:write(P0, #protocol_message_begin{
- name = atom_to_list(Function),
- type = MsgType,
- seqid = Seq
- }),
- {P2, ok} = thrift_protocol:write(P1, {Params, list_to_tuple([Function|Args])}),
- {P3, ok} = thrift_protocol:write(P2, message_end),
- {P4, ok} = thrift_protocol:flush_transport(P3),
- {ok, Client#tclient{protocol = P4}}.
+ try
+ {P1, ok} = thrift_protocol:write(P0, #protocol_message_begin{
+ name = atom_to_list(Function),
+ type = MsgType,
+ seqid = Seq
+ }),
+ {P2, ok} = thrift_protocol:write(P1, {Params, list_to_tuple([Function|Args])}),
+ {P3, ok} = thrift_protocol:write(P2, message_end),
+ {P4, ok} = thrift_protocol:flush_transport(P3),
+ {ok, Client#tclient{protocol = P4}}
+ catch
+ error:{badmatch, {_, {error, _} = Error}} -> {Error, Client}
+ end.
-spec receive_function_result(#tclient{}, atom()) -> {#tclient{}, {ok, any()} | {error, any()}}.
receive_function_result(Client = #tclient{service = Service}, Function) ->