Merge pull request #9268 from sstrigler/EMQX-7817-fix-unexpected-400

Fix unexpected 400
This commit is contained in:
Zaiming (Stone) Shi 2022-11-03 12:06:38 +01:00 committed by GitHub
commit e9d31b2f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 5 deletions

View File

@ -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,

View File

@ -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"),
@ -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(
@ -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)).

View File

@ -30,3 +30,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).

View File

@ -28,3 +28,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)。