fix(gw): return HTTP 400 for unimplemented handle call

This commit is contained in:
JimMoen 2023-12-20 03:22:54 +08:00
parent 578a231a8d
commit 465f71180a
No known key found for this signature in database
GPG Key ID: 87A520B4F76BA86D
2 changed files with 21 additions and 3 deletions

View File

@ -197,6 +197,10 @@ subscriptions(get, #{
case emqx_gateway_http:list_client_subscriptions(GwName, ClientId) of
{error, not_found} ->
return_http_error(404, "client process not found");
{error, ignored} ->
return_http_error(
400, "get subscriptions failed: unsupported"
);
{error, Reason} ->
return_http_error(400, Reason);
{ok, Subs} ->
@ -222,7 +226,13 @@ subscriptions(post, #{
)
of
{error, not_found} ->
return_http_error(404, "client process not found");
return_http_error(
404, "client process not found"
);
{error, ignored} ->
return_http_error(
400, "subscribe failed: unsupported"
);
{error, Reason} ->
return_http_error(400, Reason);
{ok, {NTopic, NSubOpts}} ->
@ -241,8 +251,14 @@ subscriptions(delete, #{
with_gateway(Name0, fun(GwName, _) ->
case lookup_topic(GwName, ClientId, Topic) of
{ok, _} ->
_ = emqx_gateway_http:client_unsubscribe(GwName, ClientId, Topic),
{204};
case emqx_gateway_http:client_unsubscribe(GwName, ClientId, Topic) of
{error, ignored} ->
return_http_error(
400, "unsubscribe failed: unsupported"
);
_ ->
{204}
end;
{error, not_found} ->
return_http_error(404, "Resource not found")
end

View File

@ -378,6 +378,8 @@ client_call(GwName, ClientId, Req) ->
of
undefined ->
{error, not_found};
ignored ->
{error, ignored};
Res ->
Res
catch