fix: return 404 instead of 400 for unknown gateway
This commit is contained in:
parent
12addc2118
commit
612e5acea8
|
@ -151,7 +151,7 @@ gateway_insta(get, #{bindings := #{name := Name0}}) ->
|
||||||
end
|
end
|
||||||
catch
|
catch
|
||||||
error:badarg ->
|
error:badarg ->
|
||||||
return_http_error(400, "Bad gateway name")
|
return_http_error(404, "Bad gateway name")
|
||||||
end;
|
end;
|
||||||
gateway_insta(put, #{
|
gateway_insta(put, #{
|
||||||
body := GwConf0,
|
body := GwConf0,
|
||||||
|
|
|
@ -66,8 +66,8 @@ t_gateway(_) ->
|
||||||
lists:foreach(fun assert_gw_unloaded/1, UnloadedGateways),
|
lists:foreach(fun assert_gw_unloaded/1, UnloadedGateways),
|
||||||
{200, NoRunningGateways} = request(get, "/gateways?status=running"),
|
{200, NoRunningGateways} = request(get, "/gateways?status=running"),
|
||||||
?assertEqual([], NoRunningGateways),
|
?assertEqual([], NoRunningGateways),
|
||||||
{400, BadReqUnknownGw} = request(get, "/gateways/unknown_gateway"),
|
{404, GwNotFoundReq} = request(get, "/gateways/unknown_gateway"),
|
||||||
assert_bad_request(BadReqUnknownGw),
|
assert_not_found(GwNotFoundReq),
|
||||||
{400, BadReqInvalidStatus} = request(get, "/gateways?status=invalid_status"),
|
{400, BadReqInvalidStatus} = request(get, "/gateways?status=invalid_status"),
|
||||||
assert_bad_request(BadReqInvalidStatus),
|
assert_bad_request(BadReqInvalidStatus),
|
||||||
{400, BadReqUCStatus} = request(get, "/gateways?status=UNLOADED"),
|
{400, BadReqUCStatus} = request(get, "/gateways?status=UNLOADED"),
|
||||||
|
@ -86,8 +86,8 @@ t_gateway(_) ->
|
||||||
t_deprecated_gateway(_) ->
|
t_deprecated_gateway(_) ->
|
||||||
{200, Gateways} = request(get, "/gateway"),
|
{200, Gateways} = request(get, "/gateway"),
|
||||||
lists:foreach(fun assert_gw_unloaded/1, Gateways),
|
lists:foreach(fun assert_gw_unloaded/1, Gateways),
|
||||||
{400, BadReq} = request(get, "/gateway/uname_gateway"),
|
{404, NotFoundReq} = request(get, "/gateway/uname_gateway"),
|
||||||
assert_bad_request(BadReq),
|
assert_not_found(NotFoundReq),
|
||||||
{201, _} = request(post, "/gateway", #{name => <<"stomp">>}),
|
{201, _} = request(post, "/gateway", #{name => <<"stomp">>}),
|
||||||
{200, StompGw1} = request(get, "/gateway/stomp"),
|
{200, StompGw1} = request(get, "/gateway/stomp"),
|
||||||
assert_feilds_apperence(
|
assert_feilds_apperence(
|
||||||
|
@ -571,3 +571,6 @@ assert_gw_unloaded(Gateway) ->
|
||||||
|
|
||||||
assert_bad_request(BadReq) ->
|
assert_bad_request(BadReq) ->
|
||||||
?assertEqual(<<"BAD_REQUEST">>, maps:get(code, BadReq)).
|
?assertEqual(<<"BAD_REQUEST">>, maps:get(code, BadReq)).
|
||||||
|
|
||||||
|
assert_not_found(NotFoundReq) ->
|
||||||
|
?assertEqual(<<"RESOURCE_NOT_FOUND">>, maps:get(code, NotFoundReq)).
|
||||||
|
|
|
@ -29,3 +29,5 @@
|
||||||
This bug was introduced in v5.0.9. For Rule-Engine's input events like `$events/message_delivered`
|
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,
|
and `$events/message_dropped`, if the message was delivered to a shared-subscription,
|
||||||
the encoding (to JSON) of the event will fail.
|
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).
|
||||||
|
|
|
@ -27,3 +27,5 @@
|
||||||
- 修复规则引擎的消息事件编码失败 [#9228](https://github.com/emqx/emqx/pull/9228)。
|
- 修复规则引擎的消息事件编码失败 [#9228](https://github.com/emqx/emqx/pull/9228)。
|
||||||
该问题在 v5.0.9 中引入:带消息的规则引擎事件,例如 `$events/message_delivered` 和
|
该问题在 v5.0.9 中引入:带消息的规则引擎事件,例如 `$events/message_delivered` 和
|
||||||
`$events/message_dropped`, 如果消息事件是共享订阅产生的,在编码(到 JSON 格式)过程中会失败。
|
`$events/message_dropped`, 如果消息事件是共享订阅产生的,在编码(到 JSON 格式)过程中会失败。
|
||||||
|
|
||||||
|
- 修复 HTTP API `/gateways` 的返回状态码,未知 Gateway 名字应返回 `404` 而不是 `400` [#9268](https://github.com/emqx/emqx/pull/9268)。
|
||||||
|
|
Loading…
Reference in New Issue