fix(emqx_bridge): don't crash checking if bridge enabled
This commit is contained in:
parent
80b81748df
commit
a325133391
|
@ -655,8 +655,7 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
||||||
invalid ->
|
invalid ->
|
||||||
?NOT_FOUND(<<"Invalid operation: ", Op/binary>>);
|
?NOT_FOUND(<<"Invalid operation: ", Op/binary>>);
|
||||||
OperFunc ->
|
OperFunc ->
|
||||||
ConfMap = emqx:get_config([bridges, BridgeType, BridgeName]),
|
try is_enabled_bridge(BridgeType, BridgeName) of
|
||||||
case maps:get(enable, ConfMap, false) of
|
|
||||||
false ->
|
false ->
|
||||||
?BAD_REQUEST(<<"Forbidden operation, bridge not enabled">>);
|
?BAD_REQUEST(<<"Forbidden operation, bridge not enabled">>);
|
||||||
true ->
|
true ->
|
||||||
|
@ -668,10 +667,22 @@ lookup_from_local_node(BridgeType, BridgeName) ->
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
?NOT_FOUND(<<"Invalid node name: ", Node/binary>>)
|
?NOT_FOUND(<<"Invalid node name: ", Node/binary>>)
|
||||||
end
|
end
|
||||||
|
catch
|
||||||
|
throw:not_found ->
|
||||||
|
?BRIDGE_NOT_FOUND(BridgeType, BridgeName)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
).
|
).
|
||||||
|
|
||||||
|
is_enabled_bridge(BridgeType, BridgeName) ->
|
||||||
|
try emqx:get_config([bridges, BridgeType, BridgeName]) of
|
||||||
|
ConfMap ->
|
||||||
|
maps:get(enable, ConfMap, false)
|
||||||
|
catch
|
||||||
|
error:{config_not_found, _} ->
|
||||||
|
throw(not_found)
|
||||||
|
end.
|
||||||
|
|
||||||
node_operation_func(<<"restart">>) -> restart_bridge_to_node;
|
node_operation_func(<<"restart">>) -> restart_bridge_to_node;
|
||||||
node_operation_func(<<"start">>) -> start_bridge_to_node;
|
node_operation_func(<<"start">>) -> start_bridge_to_node;
|
||||||
node_operation_func(<<"stop">>) -> stop_bridge_to_node;
|
node_operation_func(<<"stop">>) -> stop_bridge_to_node;
|
||||||
|
|
Loading…
Reference in New Issue