Merge pull request #9494 from sstrigler/EMQX-7992-post-trace-must-respond-with-409-on-duplicate-entry
fix: return 409 in case of duplicate
This commit is contained in:
commit
85f54220b0
|
@ -84,11 +84,16 @@ schema("/trace") ->
|
||||||
200 => hoconsc:ref(trace),
|
200 => hoconsc:ref(trace),
|
||||||
400 => emqx_dashboard_swagger:error_codes(
|
400 => emqx_dashboard_swagger:error_codes(
|
||||||
[
|
[
|
||||||
'ALREADY_EXISTS',
|
|
||||||
'DUPLICATE_CONDITION',
|
|
||||||
'INVALID_PARAMS'
|
'INVALID_PARAMS'
|
||||||
],
|
],
|
||||||
<<"trace name already exists">>
|
<<"invalid trace params">>
|
||||||
|
),
|
||||||
|
409 => emqx_dashboard_swagger:error_codes(
|
||||||
|
[
|
||||||
|
'ALREADY_EXISTS',
|
||||||
|
'DUPLICATE_CONDITION'
|
||||||
|
],
|
||||||
|
<<"trace already exists">>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -392,12 +397,12 @@ trace(post, #{body := Param}) ->
|
||||||
{ok, Trace0} ->
|
{ok, Trace0} ->
|
||||||
{200, format_trace(Trace0)};
|
{200, format_trace(Trace0)};
|
||||||
{error, {already_existed, Name}} ->
|
{error, {already_existed, Name}} ->
|
||||||
{400, #{
|
{409, #{
|
||||||
code => 'ALREADY_EXISTS',
|
code => 'ALREADY_EXISTS',
|
||||||
message => ?TO_BIN([Name, " Already Exists"])
|
message => ?TO_BIN([Name, " Already Exists"])
|
||||||
}};
|
}};
|
||||||
{error, {duplicate_condition, Name}} ->
|
{error, {duplicate_condition, Name}} ->
|
||||||
{400, #{
|
{409, #{
|
||||||
code => 'DUPLICATE_CONDITION',
|
code => 'DUPLICATE_CONDITION',
|
||||||
message => ?TO_BIN([Name, " Duplication Condition"])
|
message => ?TO_BIN([Name, " Duplication Condition"])
|
||||||
}};
|
}};
|
||||||
|
|
|
@ -149,7 +149,7 @@ t_create_failed(_Config) ->
|
||||||
{ok, Create} = request_api(post, api_path("trace"), Header, [GoodName | Trace]),
|
{ok, Create} = request_api(post, api_path("trace"), Header, [GoodName | Trace]),
|
||||||
?assertMatch(#{<<"name">> := <<"test-name-0">>}, json(Create)),
|
?assertMatch(#{<<"name">> := <<"test-name-0">>}, json(Create)),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{error, {"HTTP/1.1", 400, _}, _},
|
{error, {"HTTP/1.1", 409, _}, _},
|
||||||
request_api(post, api_path("trace"), Header, [GoodName | Trace])
|
request_api(post, api_path("trace"), Header, [GoodName | Trace])
|
||||||
),
|
),
|
||||||
|
|
||||||
|
@ -171,6 +171,16 @@ t_create_failed(_Config) ->
|
||||||
{error, {"HTTP/1.1", 400, _}, _},
|
{error, {"HTTP/1.1", 400, _}, _},
|
||||||
request_api(post, api_path("trace"), Header, [GoodName1 | Trace])
|
request_api(post, api_path("trace"), Header, [GoodName1 | Trace])
|
||||||
),
|
),
|
||||||
|
%% clear
|
||||||
|
?assertMatch({ok, _}, request_api(delete, api_path("trace"), Header, [])),
|
||||||
|
{ok, Create} = request_api(post, api_path("trace"), Header, [GoodName | Trace]),
|
||||||
|
%% new name but same trace
|
||||||
|
GoodName2 = {<<"name">>, <<"test-name-1">>},
|
||||||
|
?assertMatch(
|
||||||
|
{error, {"HTTP/1.1", 409, _}, _},
|
||||||
|
request_api(post, api_path("trace"), Header, [GoodName2 | Trace])
|
||||||
|
),
|
||||||
|
|
||||||
unload(),
|
unload(),
|
||||||
emqx_trace:clear(),
|
emqx_trace:clear(),
|
||||||
ok.
|
ok.
|
||||||
|
|
|
@ -49,4 +49,6 @@ Please note, the request body of `/bridges` API to configure MQTT brdige is chan
|
||||||
- Fix shadowing `'client.authenticate'` callbacks by `emqx_authenticator`. Now `emqx_authenticator`
|
- Fix shadowing `'client.authenticate'` callbacks by `emqx_authenticator`. Now `emqx_authenticator`
|
||||||
passes execution to the further callbacks if none of the authenticators matches [#9496](https://github.com/emqx/emqx/pull/9496).
|
passes execution to the further callbacks if none of the authenticators matches [#9496](https://github.com/emqx/emqx/pull/9496).
|
||||||
|
|
||||||
- Return `400` if query param `node` is not a known in `/trace/:id/download?node={node}` [#9478](https://github.com/emqx/emqx/pull/9478).
|
- Return `400` if query param `node` is not a known node in `/trace/:id/download?node={node}` [#9478](https://github.com/emqx/emqx/pull/9478).
|
||||||
|
|
||||||
|
- `POST /traces` to return `409` in case of duplicate [#9494](https://github.com/emqx/emqx/pull/9494).
|
||||||
|
|
|
@ -47,4 +47,6 @@ v5.0.11 或更早版本创建的配置文件,在新版本中会被自动转换
|
||||||
|
|
||||||
- 通过 `emqx_authenticator` 修复隐藏 `'client.authenticate'` 回调。 现在 `emqx_authenticator` 如果没有任何验证器匹配,则将执行传递给进一步的回调 [#9496](https://github.com/emqx/emqx/pull/9496)。
|
- 通过 `emqx_authenticator` 修复隐藏 `'client.authenticate'` 回调。 现在 `emqx_authenticator` 如果没有任何验证器匹配,则将执行传递给进一步的回调 [#9496](https://github.com/emqx/emqx/pull/9496)。
|
||||||
|
|
||||||
- 如果在调用 `/trace/:id/download?node={node}` 时,`node` 不存在,则会返回 `400` [#9478](https://github.com/emqx/emqx/pull/9478).
|
- 如果在调用 `/trace/:id/download?node={node}` 时,`node` 不存在,则会返回 `400` [#9478](https://github.com/emqx/emqx/pull/9478)。
|
||||||
|
|
||||||
|
- 当重复调用 `POST /traces` 时,将会返回 `409` ,而不再是 `400` [#9494](https://github.com/emqx/emqx/pull/9494)。
|
||||||
|
|
Loading…
Reference in New Issue