refactor(emqx_resource): catch only hocon throw exceptions
This commit is contained in:
parent
252d7e85d9
commit
cf1f19258e
|
@ -295,18 +295,20 @@ call_jsonify(Mod, Config) ->
|
||||||
-spec check_config(resource_type(), raw_resource_config()) ->
|
-spec check_config(resource_type(), raw_resource_config()) ->
|
||||||
{ok, resource_config()} | {error, term()}.
|
{ok, resource_config()} | {error, term()}.
|
||||||
check_config(ResourceType, RawConfig) when is_binary(RawConfig) ->
|
check_config(ResourceType, RawConfig) when is_binary(RawConfig) ->
|
||||||
case hocon:binary(RawConfig, #{format => richmap}) of
|
case hocon:binary(RawConfig, #{format => map}) of
|
||||||
{ok, MapConfig} ->
|
{ok, MapConfig} ->
|
||||||
case ?SAFE_CALL(hocon_tconf:check(ResourceType, MapConfig, ?HOCON_CHECK_OPTS)) of
|
check_config(ResourceType, MapConfig);
|
||||||
{error, Reason} -> {error, Reason};
|
{error, Reason} ->
|
||||||
Config -> {ok, hocon_maps:ensure_plain(Config)}
|
{error, Reason}
|
||||||
end;
|
|
||||||
Error -> Error
|
|
||||||
end;
|
end;
|
||||||
check_config(ResourceType, RawConfigTerm) ->
|
check_config(ResourceType, RawConfigTerm) ->
|
||||||
case ?SAFE_CALL(hocon_tconf:check_plain(ResourceType, RawConfigTerm, ?HOCON_CHECK_OPTS)) of
|
%% hocon_tconf map and check APIs throw exception on bad configs
|
||||||
{error, Reason} -> {error, Reason};
|
try hocon_tconf:check_plain(ResourceType, RawConfigTerm, ?HOCON_CHECK_OPTS) of
|
||||||
Config -> {ok, Config}
|
Config ->
|
||||||
|
{ok, Config}
|
||||||
|
catch
|
||||||
|
throw : Reason ->
|
||||||
|
{error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec check_and_create(instance_id(), resource_type(), raw_resource_config()) ->
|
-spec check_and_create(instance_id(), resource_type(), raw_resource_config()) ->
|
||||||
|
|
Loading…
Reference in New Issue