chore(gw): return unloaded status instead of 404

This commit is contained in:
JianBo He 2021-10-11 15:23:42 +08:00
parent ec4198c91c
commit b637764095
1 changed files with 24 additions and 4 deletions

View File

@ -92,10 +92,30 @@ gateway_insta(delete, #{bindings := #{name := Name0}}) ->
end end
end); end);
gateway_insta(get, #{bindings := #{name := Name0}}) -> gateway_insta(get, #{bindings := #{name := Name0}}) ->
with_gateway(Name0, fun(_, _) -> try
GwConf = emqx_gateway_conf:gateway(Name0), GwName = try
{200, GwConf#{<<"name">> => Name0}} binary_to_existing_atom(Name0)
end); catch _ : _ -> error(badname)
end,
case emqx_gateway:lookup(GwName) of
undefined ->
{200, #{name => GwName, status => unloaded}};
Gateway ->
GwConf = emqx_gateway_conf:gateway(Name0),
GwInfo0 = emqx_gateway_utils:unix_ts_to_rfc3339(
[created_at, started_at, stopped_at],
Gateway),
GwInfo1 = maps:with([name,
status,
created_at,
started_at,
stopped_at], GwInfo0),
{200, maps:merge(GwConf, GwInfo1)}
end
catch
error : badname ->
return_http_error(400, "Bad gateway name")
end;
gateway_insta(put, #{body := GwConf, gateway_insta(put, #{body := GwConf,
bindings := #{name := Name0} bindings := #{name := Name0}
}) -> }) ->