mirror of
https://github.com/valitydev/kds.git
synced 2024-11-06 00:05:18 +00:00
parent
c022cceb1c
commit
b2dd69cd30
@ -18,18 +18,11 @@
|
||||
handle_function(OperationID, Args, Context, Opts) ->
|
||||
scoper:scope(
|
||||
keyring_management,
|
||||
fun() ->
|
||||
try
|
||||
kds_thrift_handler_utils:filter_fun_exceptions(
|
||||
fun() ->
|
||||
handle_function_(OperationID, Args, Context, Opts)
|
||||
catch
|
||||
throw:Exception ->
|
||||
throw(Exception);
|
||||
error:{woody_error, _} = WoodyError:Stacktrace ->
|
||||
erlang:raise(error, WoodyError, Stacktrace);
|
||||
Class:_Exception:Stacktrace ->
|
||||
erlang:raise(Class, '***', Stacktrace)
|
||||
end
|
||||
end
|
||||
)
|
||||
).
|
||||
|
||||
handle_function_('StartInit', [Threshold], _Context, _Opts) ->
|
||||
@ -312,4 +305,4 @@ decode_signed_share(#'cds_SignedMasterKeyShare'{
|
||||
|
||||
-spec raise(_) -> no_return().
|
||||
raise(Exception) ->
|
||||
woody_error:raise(business, Exception).
|
||||
kds_thrift_handler_utils:raise(Exception).
|
||||
|
@ -16,18 +16,11 @@
|
||||
handle_function(OperationID, Args, Context, Opts) ->
|
||||
scoper:scope(
|
||||
keyring_storage,
|
||||
fun() ->
|
||||
try
|
||||
kds_thrift_handler_utils:filter_fun_exceptions(
|
||||
fun() ->
|
||||
handle_function_(OperationID, Args, Context, Opts)
|
||||
catch
|
||||
throw:Exception ->
|
||||
throw(Exception);
|
||||
error:{woody_error, _} = WoodyError:Stacktrace ->
|
||||
erlang:raise(error, WoodyError, Stacktrace);
|
||||
Class:_Exception:Stacktrace ->
|
||||
erlang:raise(Class, '***', Stacktrace)
|
||||
end
|
||||
end
|
||||
)
|
||||
).
|
||||
|
||||
handle_function_('GetKeyring', [], _Context, _Opts) ->
|
||||
@ -74,4 +67,4 @@ encode_keys(Keys, KeysMeta) ->
|
||||
|
||||
-spec raise(_) -> no_return().
|
||||
raise(Exception) ->
|
||||
woody_error:raise(business, Exception).
|
||||
kds_thrift_handler_utils:raise(Exception).
|
||||
|
57
apps/kds/src/kds_thrift_handler_utils.erl
Normal file
57
apps/kds/src/kds_thrift_handler_utils.erl
Normal file
@ -0,0 +1,57 @@
|
||||
-module(kds_thrift_handler_utils).
|
||||
|
||||
-export([filter_fun_exceptions/1]).
|
||||
-export([raise/1]).
|
||||
|
||||
%%
|
||||
%% API
|
||||
%%
|
||||
|
||||
-spec filter_fun_exceptions(fun()) -> fun().
|
||||
filter_fun_exceptions(Fun) ->
|
||||
fun() ->
|
||||
try
|
||||
Fun()
|
||||
catch
|
||||
throw:Exception ->
|
||||
throw(Exception);
|
||||
error:{woody_error, _} = WoodyError:Stacktrace ->
|
||||
erlang:raise(error, WoodyError, Stacktrace);
|
||||
Class:Exception:Stacktrace ->
|
||||
erlang:raise(Class, filter_error_reason(Exception), Stacktrace)
|
||||
end
|
||||
end.
|
||||
|
||||
-spec raise(_) -> no_return().
|
||||
raise(Exception) ->
|
||||
woody_error:raise(business, Exception).
|
||||
|
||||
%%
|
||||
%% Internals
|
||||
%%
|
||||
|
||||
% Known safe errors
|
||||
filter_error_reason({hash_collision_detected, _Hash} = Reason) ->
|
||||
Reason;
|
||||
% Generic safe errors
|
||||
filter_error_reason(Reason) when is_tuple(Reason) ->
|
||||
erlang:list_to_tuple([filter_error_reason(R) || R <- erlang:tuple_to_list(Reason)]);
|
||||
filter_error_reason(Reason) when is_list(Reason) ->
|
||||
[filter_error_reason(R) || R <- Reason];
|
||||
filter_error_reason(Reason) when is_map(Reason) ->
|
||||
maps:map(
|
||||
fun(_Key, Value) ->
|
||||
filter_error_reason(Value)
|
||||
end,
|
||||
Reason
|
||||
);
|
||||
filter_error_reason(Reason) when
|
||||
is_atom(Reason) orelse
|
||||
is_number(Reason) orelse
|
||||
is_reference(Reason) orelse
|
||||
is_pid(Reason)
|
||||
->
|
||||
Reason;
|
||||
% Other
|
||||
filter_error_reason(_Reason) ->
|
||||
'***'.
|
Loading…
Reference in New Issue
Block a user