new_protocol_factory(TransportFactory, Options) ->
ParsedOpts = parse_factory_options(Options, #tbp_opts{}),
F = fun() ->
- {ok, Transport} = TransportFactory(),
- thrift_binary_protocol:new(
- Transport,
- [{strict_read, ParsedOpts#tbp_opts.strict_read},
- {strict_write, ParsedOpts#tbp_opts.strict_write}])
+ case TransportFactory() of
+ {ok, Transport} ->
+ thrift_binary_protocol:new(
+ Transport,
+ [{strict_read, ParsedOpts#tbp_opts.strict_read},
+ {strict_write, ParsedOpts#tbp_opts.strict_write}]);
+ {error, Error} ->
+ {error, Error}
+ end
end,
{ok, F}.
seqid = SeqId},
Function,
ReplyType) ->
- {Proto1, MessageBegin} = thrift_protocol:read(Proto0, message_begin),
- NewClient = Client#tclient{protocol = Proto1},
- case MessageBegin of
- #protocol_message_begin{seqid = RetSeqId} when RetSeqId =/= SeqId ->
- {NewClient, {error, {bad_seq_id, SeqId}}};
-
- #protocol_message_begin{type = ?tMessageType_EXCEPTION} ->
- handle_application_exception(NewClient);
-
- #protocol_message_begin{type = ?tMessageType_REPLY} ->
- handle_reply(NewClient, Function, ReplyType)
+ case thrift_protocol:read(Proto0, message_begin) of
+ {Proto1, {error, Reason}} ->
+ NewClient = Client#tclient{protocol = Proto1},
+ {NewClient, {error, Reason}};
+ {Proto1, MessageBegin} ->
+ NewClient = Client#tclient{protocol = Proto1},
+ case MessageBegin of
+ #protocol_message_begin{seqid = RetSeqId} when RetSeqId =/= SeqId ->
+ {NewClient, {error, {bad_seq_id, SeqId}}};
+ #protocol_message_begin{type = ?tMessageType_EXCEPTION} ->
+ handle_application_exception(NewClient);
+ #protocol_message_begin{type = ?tMessageType_REPLY} ->
+ handle_reply(NewClient, Function, ReplyType)
+ end
end.
{ok, ProtocolFactory} = thrift_binary_protocol:new_protocol_factory(
TransportFactory, ProtoOpts),
- {ok, Protocol} = ProtocolFactory(),
-
- thrift_client:new(Protocol, Service).
+ case ProtocolFactory() of
+ {ok, Protocol} ->
+ thrift_client:new(Protocol, Service);
+ {error, Error} ->
+ {error, Error}
+ end.