mirror of
https://github.com/valitydev/woody_erlang.git
synced 2024-11-06 02:15:19 +00:00
Aaa 54 fix exception formatting (#115)
* Pass union value properly * Fix exception handling for simple benary messages * Fix and cleanup test * Add missing format_as_exception to meta_client() * Typo
This commit is contained in:
parent
59ec572466
commit
068bc4b3b7
@ -94,13 +94,16 @@ format_reply(Module, Service, Function, Value, Opts) ->
|
||||
ReplyType = Module:function_info(Service, Function, reply_type),
|
||||
format(ReplyType, Value, normalize_options(Opts)).
|
||||
|
||||
-spec format_exception(atom(), atom(), atom(), term(), woody:options()) ->
|
||||
-spec format_exception(atom(), atom(), atom(), term(), opts()) ->
|
||||
woody_event_handler:msg().
|
||||
format_exception(Module, Service, Function, Value, Opts) ->
|
||||
format_exception(Module, Service, Function, Value, Opts) when is_tuple(Value) ->
|
||||
{struct, struct, ExceptionTypeList} = Module:function_info(Service, Function, exceptions),
|
||||
Exception = element(1, Value),
|
||||
ReplyType = get_exception_type(Exception, ExceptionTypeList),
|
||||
format(ReplyType, Value, normalize_options(Opts)).
|
||||
format(ReplyType, Value, normalize_options(Opts));
|
||||
format_exception(_Module, _Service, _Function, Value, Opts) ->
|
||||
#{max_length := ML} = normalize_options(Opts),
|
||||
{"~s", [io_lib:format("~w", [Value], [{chars_limit, ML}])]}.
|
||||
|
||||
format(ReplyType, Value, #{max_length := ML} = Opts) when is_tuple(Value) ->
|
||||
try
|
||||
@ -215,7 +218,7 @@ format_thrift_set(Type, SetofValues, CurDepth, CL, Opts) ->
|
||||
format_list(Type, ValueList, "", CurDepth, CL, Opts, false).
|
||||
|
||||
get_exception_type(ExceptionRecord, ExceptionTypeList) ->
|
||||
[ExceptionType] =
|
||||
Result =
|
||||
lists:filtermap(
|
||||
fun ({_, _, Type = {struct, exception, {Module, Exception}}, _, _}) ->
|
||||
case Module:record_name(Exception) of
|
||||
@ -225,7 +228,12 @@ get_exception_type(ExceptionRecord, ExceptionTypeList) ->
|
||||
end,
|
||||
ExceptionTypeList
|
||||
),
|
||||
ExceptionType.
|
||||
case Result of
|
||||
[ExceptionType] ->
|
||||
ExceptionType;
|
||||
[] ->
|
||||
undefined
|
||||
end.
|
||||
|
||||
-spec format_struct(atom(), atom(), term(), non_neg_integer(), non_neg_integer(), opts()) ->
|
||||
{iolist(), non_neg_integer()}.
|
||||
|
@ -65,7 +65,8 @@
|
||||
status => status(), %% EV_CLIENT_RECEIVE | EV_SERVICE_RESULT | EV_CLIENT_RESOLVE_RESULT
|
||||
address => string(), %% EV_CLIENT_RESOLVE_RESULT
|
||||
host => string(), %% EV_CLIENT_RESOLVE_RESULT | EV_CLIENT_RESOLVE_BEGIN
|
||||
result => woody:result() | woody_error:error() %% EV_SERVICE_RESULT
|
||||
result => woody:result() | woody_error:error(), %% EV_SERVICE_RESULT
|
||||
format_as_exception => boolean() %% EV_SERVICE_RESULT
|
||||
}.
|
||||
-export_type([meta_client/0]).
|
||||
|
||||
@ -351,7 +352,7 @@ format_service_reply(#{service_schema := {Module, Service}, function:=Function,
|
||||
format_service_reply(Result, _Opts) ->
|
||||
{"~w", [Result]}.
|
||||
|
||||
get_result({_, Result}) ->
|
||||
get_result({ok, Result}) ->
|
||||
Result;
|
||||
get_result(Result) ->
|
||||
Result.
|
||||
@ -1300,6 +1301,39 @@ exception_test_() -> [
|
||||
#{}
|
||||
)
|
||||
)
|
||||
),
|
||||
?_assertEqual(
|
||||
"[1012689088739803136 1012689108264288256 1012689088534282240][client] request handled successfully: "
|
||||
"InvalidRecurrentParentPayment{details = 'Parent payment refer to another shop'}",
|
||||
format_msg_limited(
|
||||
format_event(
|
||||
?EV_SERVICE_RESULT,
|
||||
#{args=>[
|
||||
undefined,
|
||||
<<"1FToOuf532G">>,
|
||||
{payproc_InvoicePaymentParams,
|
||||
{recurrent, {payproc_RecurrentPayerParams,
|
||||
{domain_RecurrentParentPayment, <<"1FToOLnG2Ou">>, <<"1">>},
|
||||
{domain_ContactInfo, undefined, undefined}}},
|
||||
{instant, {payproc_InvoicePaymentParamsFlowInstant}},
|
||||
true, undefined, undefined, undefined, undefined}],
|
||||
deadline => undefined,
|
||||
execution_start_time => 1575444908463,
|
||||
format_as_exception => true,
|
||||
function => 'StartPayment',
|
||||
metadata => #{
|
||||
<<"user-identity.id">> => <<"1FToOJtk6YC">>,
|
||||
<<"user-identity.realm">> => <<"external">>},
|
||||
result => {payproc_InvalidRecurrentParentPayment, <<"Parent payment refer to another shop">>},
|
||||
role => client, service => 'Invoicing', service_schema =>
|
||||
{dmsl_payment_processing_thrift, 'Invoicing'}, status => ok, type => call},
|
||||
#{
|
||||
span_id => <<"1012689088534282240">>,
|
||||
trace_id => <<"1012689088739803136">>,
|
||||
parent_id => <<"1012689108264288256">>},
|
||||
#{}
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
].
|
||||
|
Loading…
Reference in New Issue
Block a user