refactor(emqx_bridge): only one place to generate same error
This commit is contained in:
parent
b256241650
commit
63606922f2
|
@ -1389,30 +1389,33 @@ validate_referenced_connectors(BridgeType, ConnectorNameBin, BridgeName) ->
|
||||||
%% N.B.: assumes that, for all bridgeV2 types, the name of the bridge type is
|
%% N.B.: assumes that, for all bridgeV2 types, the name of the bridge type is
|
||||||
%% identical to its matching connector type name.
|
%% identical to its matching connector type name.
|
||||||
try
|
try
|
||||||
ConnectorType = bridge_v2_type_to_connector_type(to_existing_atom(BridgeType)),
|
{ConnectorName, ConnectorType} = to_connector(ConnectorNameBin, BridgeType),
|
||||||
ConnectorName = to_existing_atom(ConnectorNameBin),
|
|
||||||
case emqx_config:get([connectors, ConnectorType, ConnectorName], undefined) of
|
case emqx_config:get([connectors, ConnectorType, ConnectorName], undefined) of
|
||||||
undefined ->
|
undefined ->
|
||||||
{error, #{
|
throw(not_found);
|
||||||
reason => "connector_not_found_or_wrong_type",
|
|
||||||
connector_name => ConnectorName,
|
|
||||||
connectortype => ConnectorType,
|
|
||||||
bridge_name => BridgeName,
|
|
||||||
bridge_type => BridgeType
|
|
||||||
}};
|
|
||||||
_ ->
|
_ ->
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
throw:bad_atom ->
|
throw:not_found ->
|
||||||
{error, #{
|
{error, #{
|
||||||
reason => "connector_not_found_or_wrong_type",
|
reason => "connector_not_found_or_wrong_type",
|
||||||
type => BridgeType,
|
connector_name => ConnectorNameBin,
|
||||||
bridge_name => BridgeName,
|
bridge_name => BridgeName,
|
||||||
connector_name => ConnectorNameBin
|
bridge_type => BridgeType
|
||||||
}}
|
}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
to_connector(ConnectorNameBin, BridgeType) ->
|
||||||
|
try
|
||||||
|
ConnectorType = ?MODULE:bridge_v2_type_to_connector_type(to_existing_atom(BridgeType)),
|
||||||
|
ConnectorName = to_existing_atom(ConnectorNameBin),
|
||||||
|
{ConnectorName, ConnectorType}
|
||||||
|
catch
|
||||||
|
_:_ ->
|
||||||
|
throw(not_found)
|
||||||
|
end.
|
||||||
|
|
||||||
multi_validate_referenced_connectors(Configs) ->
|
multi_validate_referenced_connectors(Configs) ->
|
||||||
Pipeline =
|
Pipeline =
|
||||||
lists:map(
|
lists:map(
|
||||||
|
|
Loading…
Reference in New Issue