Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unexpected 400 #9268

Merged
merged 1 commit into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/emqx_gateway/src/emqx_gateway_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ gateway_insta(get, #{bindings := #{name := Name0}}) ->
end
catch
error:badarg ->
return_http_error(400, "Bad gateway name")
return_http_error(404, "Bad gateway name")
end;
gateway_insta(put, #{
body := GwConf0,
Expand Down
11 changes: 7 additions & 4 deletions apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ t_gateway(_) ->
lists:foreach(fun assert_gw_unloaded/1, UnloadedGateways),
{200, NoRunningGateways} = request(get, "/gateways?status=running"),
?assertEqual([], NoRunningGateways),
{400, BadReqUnknownGw} = request(get, "/gateways/unknown_gateway"),
assert_bad_request(BadReqUnknownGw),
{404, GwNotFoundReq} = request(get, "/gateways/unknown_gateway"),
assert_not_found(GwNotFoundReq),
{400, BadReqInvalidStatus} = request(get, "/gateways?status=invalid_status"),
assert_bad_request(BadReqInvalidStatus),
{400, BadReqUCStatus} = request(get, "/gateways?status=UNLOADED"),
Expand All @@ -86,8 +86,8 @@ t_gateway(_) ->
t_deprecated_gateway(_) ->
{200, Gateways} = request(get, "/gateway"),
lists:foreach(fun assert_gw_unloaded/1, Gateways),
{400, BadReq} = request(get, "/gateway/uname_gateway"),
assert_bad_request(BadReq),
{404, NotFoundReq} = request(get, "/gateway/uname_gateway"),
assert_not_found(NotFoundReq),
{201, _} = request(post, "/gateway", #{name => <<"stomp">>}),
{200, StompGw1} = request(get, "/gateway/stomp"),
assert_feilds_apperence(
Expand Down Expand Up @@ -571,3 +571,6 @@ assert_gw_unloaded(Gateway) ->

assert_bad_request(BadReq) ->
?assertEqual(<<"BAD_REQUEST">>, maps:get(code, BadReq)).

assert_not_found(NotFoundReq) ->
?assertEqual(<<"RESOURCE_NOT_FOUND">>, maps:get(code, NotFoundReq)).
2 changes: 2 additions & 0 deletions changes/v5.0.10-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@
This bug was introduced in v5.0.9. For Rule-Engine's input events like `$events/message_delivered`
and `$events/message_dropped`, if the message was delivered to a shared-subscription,
the encoding (to JSON) of the event will fail.

- Fix bad HTTP response status code for `/gateways` API, when Gateway name is unknown, it should return `404` instead of `400` [#9268](https://github.com/emqx/emqx/pull/9268).
2 changes: 2 additions & 0 deletions changes/v5.0.10-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
- 修复规则引擎的消息事件编码失败 [#9228](https://github.com/emqx/emqx/pull/9228)。
该问题在 v5.0.9 中引入:带消息的规则引擎事件,例如 `$events/message_delivered` 和
`$events/message_dropped`, 如果消息事件是共享订阅产生的,在编码(到 JSON 格式)过程中会失败。

- 修复 HTTP API `/gateways` 的返回状态码,未知 Gateway 名字应返回 `404` 而不是 `400` [#9268](https://github.com/emqx/emqx/pull/9268)。